Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model_id = "WizardLM/WizardCoder-Python-13B-V1.0"
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
model_id,
|
| 10 |
+
device_map="auto",
|
| 11 |
+
torch_dtype=torch.float16,
|
| 12 |
+
trust_remote_code=True
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
def generate(prompt):
|
| 16 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 17 |
+
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7)
|
| 18 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 19 |
+
|
| 20 |
+
demo = gr.Interface(fn=generate, inputs="text", outputs="text", title="WizardCoder API")
|
| 21 |
+
demo.launch()
|