Adhem88 commited on
Commit
ed450aa
·
verified ·
1 Parent(s): 9d88ba3

Create app

Browse files
Files changed (1) hide show
  1. app +26 -0
app ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # تحميل نموذج دردشة مجاني من Hugging Face
5
+ chatbot = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta")
6
+
7
+ def chat_with_ai(message, history=[]):
8
+ prompt = ""
9
+ for user_msg, bot_msg in history:
10
+ prompt += f"User: {user_msg}\nAI: {bot_msg}\n"
11
+ prompt += f"User: {message}\nAI:"
12
+
13
+ response = chatbot(
14
+ prompt,
15
+ max_new_tokens=200,
16
+ do_sample=True,
17
+ temperature=0.7,
18
+ top_p=0.9
19
+ )
20
+
21
+ reply = response[0]["generated_text"].split("AI:")[-1].strip()
22
+ history.append((message, reply))
23
+ return reply, history
24
+
25
+ demo = gr.ChatInterface(fn=chat_with_ai, title="Adhem AI Chatbot 🤖 (Free Model)")
26
+ demo.launch(share=True)