Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
@@ -1,3 +1,22 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
|
4 |
+
# 模型和分词器的名称
|
5 |
+
model_name = "Qwen2.5-7B-Instruct"
|
6 |
+
|
7 |
+
# 加载模型和分词器
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
10 |
+
|
11 |
+
# 定义生成文本的函数
|
12 |
+
def generate_text(input_text):
|
13 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
14 |
+
outputs = model.generate(**inputs, max_length=100)
|
15 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
+
return generated_text
|
17 |
+
|
18 |
+
# 创建 Gradio 接口
|
19 |
+
iface = gr.Interface(fn=generate_text, inputs="text", outputs="text")
|
20 |
+
|
21 |
+
# 启动 Gradio 接口
|
22 |
+
iface.launch()
|