Nitzantry1 commited on
Commit
8239d17
โ€ข
1 Parent(s): 53a67f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -4,20 +4,26 @@ import gradio as gr
4
  # ื—ื™ื‘ื•ืจ ืœ-Space ืขื ื”ืžื•ื“ืœ ื‘-Hugging Face
5
  client = Client("dicta-il/dictalm2.0-instruct-demo")
6
 
7
- def chat_with_model(prompt):
 
8
  result = client.predict(
9
  message=prompt,
10
  api_name="/chat"
11
  )
12
- return result
13
 
14
- # ื™ืฆื™ืจืช ืžืžืฉืง ืžืชืงื“ื ืขื Gradio
15
- with gr.Blocks() as demo:
16
- gr.Markdown("# Chat with DictaLM Model")
 
17
  with gr.Row():
18
- input_text = gr.Textbox(label="Enter your prompt here", lines=3)
19
- output_text = gr.Textbox(label="Model's response", lines=5)
20
- submit_btn = gr.Button("Submit")
21
- submit_btn.click(chat_with_model, inputs=input_text, outputs=output_text)
 
 
 
 
22
 
23
  demo.launch()
 
4
  # ื—ื™ื‘ื•ืจ ืœ-Space ืขื ื”ืžื•ื“ืœ ื‘-Hugging Face
5
  client = Client("dicta-il/dictalm2.0-instruct-demo")
6
 
7
+ def chat_with_model(history):
8
+ prompt = history[-1]["user"]
9
  result = client.predict(
10
  message=prompt,
11
  api_name="/chat"
12
  )
13
+ return history + [{"user": prompt, "bot": result}]
14
 
15
+ # ื™ืฆื™ืจืช ืžืžืฉืง ืžืชืงื“ื ืขื Gradio ื‘ืฆื•ืจืช ืฆ'ื˜-ื‘ื•ื˜
16
+ with gr.Blocks(theme="default") as demo:
17
+ gr.Markdown("# ืฆ'ืื˜ ืขื ืžื•ื“ืœ DictaLM", elem_id="title")
18
+ chatbot = gr.Chatbot(label="ืฆ'ืื˜ ืขื ืžื•ื“ืœ DictaLM")
19
  with gr.Row():
20
+ user_input = gr.Textbox(placeholder="ื”ื›ื ืก ืืช ื”ื”ื•ื“ืขื” ืฉืœืš ื›ืืŸ...", label="", lines=1)
21
+ send_button = gr.Button("ืฉืœื—")
22
+
23
+ def user_chat(history, message):
24
+ return history + [{"user": message}], ""
25
+
26
+ send_button.click(user_chat, inputs=[chatbot, user_input], outputs=[chatbot, user_input], queue=False)
27
+ send_button.click(chat_with_model, inputs=chatbot, outputs=chatbot)
28
 
29
  demo.launch()