tikosoft commited on
Commit
b0a664c
·
verified ·
1 Parent(s): 65351a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -19
app.py CHANGED
@@ -1,32 +1,17 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # نموذج عربي مفتوح وخفيف للعمل مباشرة على Hugging Face Spaces
5
- chatbot = pipeline(
6
- "text-generation",
7
- model="akhooli/gpt2-small-arabic",
8
- tokenizer="akhooli/gpt2-small-arabic"
9
- )
10
 
11
  def chat(message, history=[]):
12
  prompt = f"المحادثة:\nالمستخدم: {message}\nالمساعد:"
13
- response = chatbot(
14
- prompt,
15
- max_length=80,
16
- num_return_sequences=1,
17
- do_sample=True,
18
- temperature=0.7
19
- )[0]["generated_text"]
20
  reply = response.split("المساعد:")[-1].strip()
21
  history.append((message, reply))
22
  return history, history
23
 
24
  with gr.Blocks() as demo:
25
- gr.ChatInterface(
26
- fn=chat,
27
- title="شات عربي مجاني",
28
- description="بوت دردشة عربي مبسط يعمل عبر Hugging Face",
29
- theme="soft"
30
- )
31
 
32
  demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # نموذج عربي مفتوح وخفيف
5
+ chatbot = pipeline("text-generation", model="akhooli/gpt2-small-arabic", tokenizer="akhooli/gpt2-small-arabic")
 
 
 
 
6
 
7
  def chat(message, history=[]):
8
  prompt = f"المحادثة:\nالمستخدم: {message}\nالمساعد:"
9
+ response = chatbot(prompt, max_length=80, num_return_sequences=1, do_sample=True, temperature=0.7)[0]["generated_text"]
 
 
 
 
 
 
10
  reply = response.split("المساعد:")[-1].strip()
11
  history.append((message, reply))
12
  return history, history
13
 
14
  with gr.Blocks() as demo:
15
+ gr.ChatInterface(fn=chat, title="شات عربي مجاني", description="بوت دردشة عربي مبسط يعمل عبر Hugging Face", theme="soft")
 
 
 
 
 
16
 
17
  demo.launch()