ohalkhateeb commited on
Commit
dbd7b96
·
verified ·
1 Parent(s): c30f47d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -46,7 +46,6 @@ def get_response(query, k=3):
46
  return response.split(query)[-1].strip()
47
 
48
  # Gradio interface
49
-
50
  import gradio as gr
51
 
52
  # Print current Gradio version
@@ -56,26 +55,29 @@ print(f"Using Gradio version: {gradio_version}")
56
  def get_response(user_message):
57
  return f"رد تلقائي: {user_message}" # Replace with your AI model
58
 
59
- # Load CSS content from file (ensure 'custom.css' exists in your working directory)
60
  css_path = "custom.css"
61
  with open(css_path, "r", encoding="utf-8") as f:
62
  custom_css = f.read()
63
 
64
  with gr.Blocks(title="المتحدث الآلي للتشريعات المحلية لإمارة دبي", css=custom_css) as demo:
65
- gr.Markdown("# Dubai Legislation Chatbot\nاسأل أي سؤال حول تشريعات دبي - نسخة تجريبية (تصميم وتنفيذ م. أسامة الخطيب)", elem_id="title")
66
  chatbot = gr.Chatbot(elem_id="chatbot", type="messages")
67
  msg = gr.Textbox(placeholder="اكتب سؤالك هنا...", rtl=True, elem_id="input-box")
68
  clear = gr.Button("مسح", elem_id="clear-btn")
69
-
70
  def user(user_message, history):
71
- history.append([user_message, None])
 
72
  return "", history
73
 
74
  def bot(history):
75
- history[-1][1] = get_response(history[-1][0])
 
76
  return history
77
 
78
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(bot, chatbot, chatbot)
79
  clear.click(lambda: [], None, chatbot, queue=False)
80
 
81
  demo.launch(share=True)
 
 
46
  return response.split(query)[-1].strip()
47
 
48
  # Gradio interface
 
49
  import gradio as gr
50
 
51
  # Print current Gradio version
 
55
  def get_response(user_message):
56
  return f"رد تلقائي: {user_message}" # Replace with your AI model
57
 
58
+ # Load custom CSS from file
59
  css_path = "custom.css"
60
  with open(css_path, "r", encoding="utf-8") as f:
61
  custom_css = f.read()
62
 
63
  with gr.Blocks(title="المتحدث الآلي للتشريعات المحلية لإمارة دبي", css=custom_css) as demo:
64
+ gr.Markdown("# فريق الذكاء الاصطناعي\nاسأل أي سؤال حول تشريعات دبي - نسخة تجريبية (تصميم وتنفيذ م. أسامة الخطيب)", elem_id="title")
65
  chatbot = gr.Chatbot(elem_id="chatbot", type="messages")
66
  msg = gr.Textbox(placeholder="اكتب سؤالك هنا...", rtl=True, elem_id="input-box")
67
  clear = gr.Button("مسح", elem_id="clear-btn")
68
+
69
  def user(user_message, history):
70
+ history = history or []
71
+ history.append({"role": "user", "content": user_message})
72
  return "", history
73
 
74
  def bot(history):
75
+ user_message = history[-1]["content"]
76
+ history.append({"role": "assistant", "content": get_response(user_message)})
77
  return history
78
 
79
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(bot, chatbot, chatbot)
80
  clear.click(lambda: [], None, chatbot, queue=False)
81
 
82
  demo.launch(share=True)
83
+