Nitzantry1 commited on
Commit
d8cb72d
ยท
verified ยท
1 Parent(s): d1de333

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -5,19 +5,18 @@ import gradio as gr
5
  client = Client("dicta-il/dictalm2.0-instruct-demo")
6
 
7
  def chat_with_model(history):
 
8
  prompt = history[-1]["content"]
9
- result = client.predict(
10
- message=prompt,
11
- api_name="/chat"
12
- )
13
  return history + [{"role": "user", "content": prompt}, {"role": "bot", "content": result}]
14
 
15
  # ื™ืฆื™ืจืช ืžืžืฉืง ืžืชืงื“ื ืขื Gradio ื‘ืฆื•ืจืช ืฆ'ื˜-ื‘ื•ื˜ ื‘ืกื’ื ื•ืŸ ืืงื“ืžื™
16
  with gr.Blocks(theme="default") as demo:
17
  gr.HTML("""
18
  <div style="background-color: #f5f5f5; padding: 20px; text-align: center;">
19
- <h1 style="color: #003366; font-family: 'Trebuchet MS', sans-serif;">ืฆ'ืื˜ ืขื ืžื•ื“ืœ DictaLM</h1>
20
- <p style="font-family: 'Trebuchet MS', sans-serif; color: #333;">ื‘ืจื•ื›ื™ื ื”ื‘ืื™ื ืœืฆ'ืื˜ ื”ืื™ื ื˜ืจืืงื˜ื™ื‘ื™ ืฉืœื ื•, ื”ืžืืคืฉืจ ืœื›ื ืœื”ืชื ืกื•ืช ื‘ืฉื™ื—ื” ืขื ืžื•ื“ืœ AI ืžืชืงื“ื.</p>
21
  </div>
22
  """)
23
  chatbot = gr.Chatbot(label="ืฆ'ืื˜ ืขื ืžื•ื“ืœ DictaLM", type="messages")
@@ -26,12 +25,15 @@ with gr.Blocks(theme="default") as demo:
26
  send_button = gr.Button("ืฉืœื—")
27
 
28
  def user_chat(history, message):
 
29
  return history + [{"role": "user", "content": message}], ""
30
 
31
- # ืชืžื™ื›ื” ื‘ืœื—ื™ืฆื” ืขืœ Enter ื‘ื ื•ืกืฃ ืœืœื—ืฆืŸ "ืฉืœื—"
32
- user_input.submit(user_chat, inputs=[chatbot, user_input], outputs=[chatbot, user_input], queue=False)
33
- user_input.submit(chat_with_model, inputs=chatbot, outputs=chatbot)
34
- send_button.click(user_chat, inputs=[chatbot, user_input], outputs=[chatbot, user_input], queue=False)
35
- send_button.click(chat_with_model, inputs=chatbot, outputs=chatbot)
 
 
36
 
37
  demo.launch()
 
5
  client = Client("dicta-il/dictalm2.0-instruct-demo")
6
 
7
  def chat_with_model(history):
8
+ # ืงื‘ืœืช ื”ื”ื•ื“ืขื” ื”ืื—ืจื•ื ื” ืฉื ืฉืœื—ื” ืขืœ ื™ื“ื™ ื”ืžืฉืชืžืฉ
9
  prompt = history[-1]["content"]
10
+ # ืฉืœื™ื—ืช ื”ื”ื•ื“ืขื” ืœืžื•ื“ืœ ื•ืงื‘ืœืช ืชื’ื•ื‘ื”
11
+ result = client.predict(message=prompt, api_name="/chat")
 
 
12
  return history + [{"role": "user", "content": prompt}, {"role": "bot", "content": result}]
13
 
14
  # ื™ืฆื™ืจืช ืžืžืฉืง ืžืชืงื“ื ืขื Gradio ื‘ืฆื•ืจืช ืฆ'ื˜-ื‘ื•ื˜ ื‘ืกื’ื ื•ืŸ ืืงื“ืžื™
15
  with gr.Blocks(theme="default") as demo:
16
  gr.HTML("""
17
  <div style="background-color: #f5f5f5; padding: 20px; text-align: center;">
18
+ <h1 style="color: #003366; font-family: Arial, sans-serif;">ืฆ'ืื˜ ืขื ืžื•ื“ืœ DictaLM</h1>
19
+ <p style="font-family: Arial, sans-serif; color: #333;">ื‘ืจื•ื›ื™ื ื”ื‘ืื™ื ืœืฆ'ืื˜ ื”ืื™ื ื˜ืจืืงื˜ื™ื‘ื™ ืฉืœื ื•, ื”ืžืืคืฉืจ ืœื›ื ืœื”ืชื ืกื•ืช ื‘ืฉื™ื—ื” ืขื ืžื•ื“ืœ AI ืžืชืงื“ื.</p>
20
  </div>
21
  """)
22
  chatbot = gr.Chatbot(label="ืฆ'ืื˜ ืขื ืžื•ื“ืœ DictaLM", type="messages")
 
25
  send_button = gr.Button("ืฉืœื—")
26
 
27
  def user_chat(history, message):
28
+ # ื”ื•ืกืคืช ื”ื•ื“ืขืช ื”ืžืฉืชืžืฉ ืœื”ื™ืกื˜ื•ืจื™ื” ืœืคื ื™ ืฉืœื™ื—ืช ื”ืฉืืœื” ืœืžื•ื“ืœ
29
  return history + [{"role": "user", "content": message}], ""
30
 
31
+ # ืฉืœื™ื—ืช ื”ื”ื•ื“ืขื” ื’ื ื‘ืœื—ื™ืฆื” ืขืœ Enter ื•ื’ื ืขืœ ื™ื“ื™ ืœื—ื™ืฆื” ืขืœ ื›ืคืชื•ืจ "ืฉืœื—"
32
+ user_input.submit(fn=user_chat, inputs=[chatbot, user_input], outputs=[chatbot, user_input], queue=False).then(
33
+ fn=chat_with_model, inputs=chatbot, outputs=chatbot
34
+ )
35
+ send_button.click(fn=user_chat, inputs=[chatbot, user_input], outputs=[chatbot, user_input], queue=False).then(
36
+ fn=chat_with_model, inputs=chatbot, outputs=chatbot
37
+ )
38
 
39
  demo.launch()