Spaces:
Runtime error
Runtime error
from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration | |
import gradio as gr | |
tokenizer = BlenderbotTokenizer.from_pretrained("facebook/blenderbot-1B-distill") | |
model = BlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-1B-distill") | |
conversation_history = [] | |
def chat(user_input): | |
conversation_history.append("أنت: " + user_input) | |
context = "\n".join(conversation_history) | |
inputs = tokenizer([context], return_tensors="pt", truncation=True, max_length=512) | |
reply_ids = model.generate(**inputs, max_new_tokens=100) | |
reply_text = tokenizer.decode(reply_ids[0], skip_special_tokens=True) | |
conversation_history.append("🤖: " + reply_text) | |
return reply_text | |
iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="🤖 روبوت دردشة ذكي") | |
iface.launch() | |