tikosoft commited on
Commit
aff16c3
·
verified ·
1 Parent(s): c96677f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -1,19 +1,31 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # نموذج عربي خفيف وسريع
5
- chatbot = pipeline("text-generation", model="asafaya/bert-base-arabic")
 
 
 
 
6
 
7
  def chat(message, history=[]):
8
- response = chatbot(message, max_length=50, do_sample=True, temperature=0.7)[0]["generated_text"]
9
- history.append((message, response))
 
 
 
 
 
 
 
 
10
  return history, history
11
 
12
  with gr.Blocks() as demo:
13
  gr.ChatInterface(
14
  fn=chat,
15
  title="شات عربي مجاني",
16
- description="بوت دردشة عربي بسيط وسريع",
17
  theme="soft"
18
  )
19
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # نموذج عربي مولد نصوص خفيف
5
+ chatbot = pipeline(
6
+ "text-generation",
7
+ model="aubmindlab/aragpt2-small",
8
+ tokenizer="aubmindlab/aragpt2-small"
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