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 AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
|
| 4 |
+
# 加载模型和分词器
|
| 5 |
+
model_name = "allenai/OLMo-7B-0724-Instruct-hf"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
|
| 8 |
+
|
| 9 |
+
# 定义生成响应的函数
|
| 10 |
+
def generate_response(prompt):
|
| 11 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 12 |
+
outputs = model.generate(inputs.input_ids, max_length=100)
|
| 13 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 14 |
+
|
| 15 |
+
# 使用 Gradio 创建界面
|
| 16 |
+
iface = gr.Interface(fn=generate_response, inputs="text", outputs="text", title="OLMo-7B Chatbot")
|
| 17 |
+
iface.launch()
|