Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import AutoTokenizer, AutoModelForCausalLM | |
# 加载模型和分词器 | |
model_name = "allenai/OLMo-7B-0724-Instruct-hf" | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto") | |
# 定义生成响应的函数 | |
def generate_response(prompt): | |
inputs = tokenizer(prompt, return_tensors="pt") | |
outputs = model.generate(inputs.input_ids, max_length=100) | |
return tokenizer.decode(outputs[0], skip_special_tokens=True) | |
# 使用 Gradio 创建界面 | |
iface = gr.Interface(fn=generate_response, inputs="text", outputs="text", title="OLMo-7B Chatbot") | |
iface.launch() | |