Spaces:
Runtime error
Runtime error
huolongguo10
commited on
Commit
·
e69cda8
1
Parent(s):
d982a8e
app.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
# torch.set_default_device("cuda")
|
5 |
+
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype="auto", trust_remote_code=True)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2", trust_remote_code=True)
|
8 |
+
def greet(text):
|
9 |
+
inputs = tokenizer(text, return_tensors="pt", return_attention_mask=False)
|
10 |
+
|
11 |
+
outputs = model.generate(**inputs, max_length=200)
|
12 |
+
_text = tokenizer.batch_decode(outputs)[0]
|
13 |
+
return _text
|
14 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
15 |
+
demo.launch()
|