Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
tokenizer = AutoTokenizer.from_pretrained("baichuan-inc/baichuan-7B", trust_remote_code=True)
|
4 |
+
model = AutoModelForCausalLM.from_pretrained("baichuan-inc/baichuan-7B", device_map="auto", trust_remote_code=True)
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
def greet(name):
|
9 |
+
# inputs = tokenizer('登鹳雀楼->王之涣\n夜雨寄北->', return_tensors='pt')
|
10 |
+
inputs = tokenizer(name, return_tensors='pt')
|
11 |
+
inputs = inputs.to('cuda:0')
|
12 |
+
pred = model.generate(**inputs, max_new_tokens=64,repetition_penalty=1.1)
|
13 |
+
result = tokenizer.decode(pred.cpu()[0], skip_special_tokens=True)
|
14 |
+
return "Hello:: " + result + "::!!"
|
15 |
+
|
16 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
17 |
+
iface.launch()
|