Spaces:
Runtime error
Runtime error
Build AI Chatbots in Minutes
Browse filesCreate fully functional AI chatbots
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
tokenizer = BlenderbotTokenizer.from_pretrained("facebook/blenderbot-1B-distill")
|
5 |
+
model = BlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-1B-distill")
|
6 |
+
|
7 |
+
conversation_history = []
|
8 |
+
|
9 |
+
def chat(user_input):
|
10 |
+
conversation_history.append("أنت: " + user_input)
|
11 |
+
context = "\n".join(conversation_history)
|
12 |
+
inputs = tokenizer([context], return_tensors="pt", truncation=True, max_length=512)
|
13 |
+
reply_ids = model.generate(**inputs, max_new_tokens=100)
|
14 |
+
reply_text = tokenizer.decode(reply_ids[0], skip_special_tokens=True)
|
15 |
+
conversation_history.append("🤖: " + reply_text)
|
16 |
+
return reply_text
|
17 |
+
|
18 |
+
iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="🤖 روبوت دردشة ذكي")
|
19 |
+
iface.launch()
|