Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
model_id = "microsoft/phi-2"
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 7 |
+
|
| 8 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 9 |
+
|
| 10 |
+
def chat(msg):
|
| 11 |
+
out = pipe(msg, max_new_tokens=150)[0]['generated_text']
|
| 12 |
+
return out
|
| 13 |
+
|
| 14 |
+
gr.Interface(fn=chat, inputs="text", outputs="text").launch()
|