mobarmg commited on
Commit
73aeb88
·
verified ·
1 Parent(s): f3eb4d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -21
app.py CHANGED
@@ -31,6 +31,12 @@ def generate_response(message, history, num_beams=4, temperature=0.99, do_sample
31
 
32
  return pred_sentiment
33
 
 
 
 
 
 
 
34
  # CSS for RTL support and styling
35
  css = """
36
  .gradio-container {direction: rtl;}
@@ -59,35 +65,26 @@ with gr.Blocks(css=css) as demo:
59
  top_p = gr.Slider(0.0, 1.0, value=0.9, step=0.01, label="Top-P")
60
 
61
  # Example prompts
62
- with gr.Accordion("أمثلة", open=False):
63
- gr.Examples(
64
- [
65
- ["اكتب مقال عن الذكاء الصناعي"],
66
- ["اكتب قصة قصيرة عن النجاح"],
67
- ["كيف يمكن المحافظة على حياه صحية"]
68
- ],
69
- inputs=msg
70
- )
71
 
72
  # Set up event handlers
73
  submit_btn.click(
74
- generate_response,
75
  inputs=[msg, chatbot, num_beams, temperature, do_sample, top_k, top_p],
76
- outputs=[chatbot],
77
- ).then(
78
- lambda: "",
79
- None,
80
- [msg]
81
  )
82
 
83
  msg.submit(
84
- generate_response,
85
  inputs=[msg, chatbot, num_beams, temperature, do_sample, top_k, top_p],
86
- outputs=[chatbot],
87
- ).then(
88
- lambda: "",
89
- None,
90
- [msg]
91
  )
92
 
93
  clear_btn.click(lambda: None, None, chatbot, queue=False)
 
31
 
32
  return pred_sentiment
33
 
34
+ # Properly format the chat message handler
35
+ def respond(message, chat_history, num_beams, temperature, do_sample, top_k, top_p):
36
+ bot_message = generate_response(message, chat_history, num_beams, temperature, do_sample, top_k, top_p)
37
+ chat_history.append((message, bot_message))
38
+ return "", chat_history
39
+
40
  # CSS for RTL support and styling
41
  css = """
42
  .gradio-container {direction: rtl;}
 
65
  top_p = gr.Slider(0.0, 1.0, value=0.9, step=0.01, label="Top-P")
66
 
67
  # Example prompts
68
+ examples = gr.Examples(
69
+ examples=[
70
+ ["اكتب مقال عن الذكاء الصناعي"],
71
+ ["اكتب قصة قصيرة عن النجاح"],
72
+ ["كيف يمكن المحافظة على حياه صحية"]
73
+ ],
74
+ inputs=msg
75
+ )
 
76
 
77
  # Set up event handlers
78
  submit_btn.click(
79
+ respond,
80
  inputs=[msg, chatbot, num_beams, temperature, do_sample, top_k, top_p],
81
+ outputs=[msg, chatbot]
 
 
 
 
82
  )
83
 
84
  msg.submit(
85
+ respond,
86
  inputs=[msg, chatbot, num_beams, temperature, do_sample, top_k, top_p],
87
+ outputs=[msg, chatbot]
 
 
 
 
88
  )
89
 
90
  clear_btn.click(lambda: None, None, chatbot, queue=False)