Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -40,24 +40,27 @@ def get_response(query, k=3):
|
|
40 |
max_new_tokens=200,
|
41 |
do_sample=True,
|
42 |
temperature=0.7,
|
43 |
-
top_p=0.9
|
|
|
44 |
)
|
45 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
46 |
return response.split(query)[-1].strip()
|
47 |
|
48 |
# Gradio interface
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
54 |
|
55 |
def user(user_message, history):
|
56 |
return "", history + [[user_message, None]]
|
57 |
|
58 |
def bot(history):
|
59 |
user_message = history[-1][0]
|
60 |
-
bot_message = get_response(user_message)
|
61 |
history[-1][1] = bot_message
|
62 |
return history
|
63 |
|
@@ -66,4 +69,11 @@ with gr.Blocks(title="Dubai Legislation Chatbot") as demo:
|
|
66 |
)
|
67 |
clear.click(lambda: None, None, chatbot, queue=False)
|
68 |
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
max_new_tokens=200,
|
41 |
do_sample=True,
|
42 |
temperature=0.7,
|
43 |
+
top_p=0.9,
|
44 |
+
return_full_text=False
|
45 |
)
|
46 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
47 |
return response.split(query)[-1].strip()
|
48 |
|
49 |
# Gradio interface
|
50 |
+
import gradio as gr
|
51 |
+
|
52 |
+
with gr.Blocks(title="المتحدث الآلي للتشريعات المحلية لإمارة دبي") as demo:
|
53 |
+
gr.Markdown("# Dubai Legislation Chatbot\nاسأل أي سؤال حول تشريعات دبي- نسخة تجريبة (تصميم وتنفيذ م.أسامة الخطيب")
|
54 |
+
chatbot = gr.Chatbot(elem_id="chatbot") # Assign an ID for CSS targeting
|
55 |
+
msg = gr.Textbox(placeholder="اكتب سؤالك هنا...", rtl=True)
|
56 |
+
clear = gr.Button("مسح")
|
57 |
|
58 |
def user(user_message, history):
|
59 |
return "", history + [[user_message, None]]
|
60 |
|
61 |
def bot(history):
|
62 |
user_message = history[-1][0]
|
63 |
+
bot_message = get_response(user_message) # Your response function
|
64 |
history[-1][1] = bot_message
|
65 |
return history
|
66 |
|
|
|
69 |
)
|
70 |
clear.click(lambda: None, None, chatbot, queue=False)
|
71 |
|
72 |
+
# Launch with custom CSS
|
73 |
+
demo.launch(css="""
|
74 |
+
#chatbot {
|
75 |
+
direction: rtl;
|
76 |
+
text-align: right;
|
77 |
+
width: 100%;
|
78 |
+
}
|
79 |
+
""", share=True)
|