Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -139,7 +139,7 @@ label {
|
|
139 |
}
|
140 |
|
141 |
|
142 |
-
|
143 |
font-family: 'Cairo', sans-serif !important;
|
144 |
background-color: #FFFBE6; /* Light gray background for user messages */
|
145 |
border-radius: 10px;
|
@@ -147,7 +147,7 @@ label {
|
|
147 |
margin-bottom: 10px;
|
148 |
}
|
149 |
|
150 |
-
|
151 |
font-family: 'Cairo', sans-serif !important;
|
152 |
background-color: #E7FBE6; /* Light cyan background for bot messages */
|
153 |
border-radius: 10px;
|
@@ -155,14 +155,13 @@ label {
|
|
155 |
margin-bottom: 10px;
|
156 |
}
|
157 |
|
158 |
-
|
159 |
#chatbox .message.bot img {
|
160 |
margin-right: 10px;
|
161 |
}
|
162 |
|
163 |
.custom-submit-button {
|
164 |
background-color: #E68369 !important;
|
165 |
-
color: whit !important;
|
166 |
border: none !important;
|
167 |
border-radius: 5px !important;
|
168 |
padding: 10px 20px !important;
|
@@ -227,6 +226,10 @@ def upload_pdf(pdf_file):
|
|
227 |
def chat(user_input):
|
228 |
global chathistory, vectorstore
|
229 |
|
|
|
|
|
|
|
|
|
230 |
|
231 |
prompt = f"""
|
232 |
You are an expert Arabic-language assistant specialized in analyzing and responding to queries about Arabic PDF documents. Your responses should be precise, informative, and reflect the professional tone and structure expected in formal Arabic communication. Focus on extracting and presenting relevant information from the document clearly and systematically, while avoiding colloquial or informal language.
|
@@ -253,7 +256,7 @@ def chat(user_input):
|
|
253 |
tts.save(audio_file)
|
254 |
|
255 |
history_display = [(msg["user_content"], msg["bot_content"]) for msg in chathistory]
|
256 |
-
return history_display, audio_file
|
257 |
|
258 |
with gr.Blocks(css=custom_css) as demo:
|
259 |
with gr.Row():
|
@@ -267,7 +270,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
267 |
submit_button_pdf = gr.Button("ارفع الملف", interactive=False)
|
268 |
with gr.Row():
|
269 |
with gr.Column(scale=3):
|
270 |
-
chatbot = gr.Chatbot(label="الشات",
|
271 |
|
272 |
with gr.Row():
|
273 |
chat_input = gr.Textbox(label="💬", rtl=True, visible=False, placeholder="أدخل سؤالك هنا ..", elem_id="inputbox", lines=2)
|
@@ -312,7 +315,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
312 |
submit_button_pdf.click(process_pdf_and_enable_components, inputs=pdf_input, outputs=[output_label, submit_button_chat, submit_button_pdf, chatbot, chat_input, audio_output, clear_btn])
|
313 |
clear_btn.click(clear_chat, outputs=[chat_input, audio_output])
|
314 |
# Chat button connection
|
315 |
-
submit_button_chat.click(chat, inputs=chat_input, outputs=[chatbot, audio_output])
|
316 |
|
317 |
|
318 |
# Launch the Gradio app
|
|
|
139 |
}
|
140 |
|
141 |
|
142 |
+
.arabic-chatbox .message.user {
|
143 |
font-family: 'Cairo', sans-serif !important;
|
144 |
background-color: #FFFBE6; /* Light gray background for user messages */
|
145 |
border-radius: 10px;
|
|
|
147 |
margin-bottom: 10px;
|
148 |
}
|
149 |
|
150 |
+
.arabic-chatbox .message.bot {
|
151 |
font-family: 'Cairo', sans-serif !important;
|
152 |
background-color: #E7FBE6; /* Light cyan background for bot messages */
|
153 |
border-radius: 10px;
|
|
|
155 |
margin-bottom: 10px;
|
156 |
}
|
157 |
|
158 |
+
.arabic-chatbox .message.user img,
|
159 |
#chatbox .message.bot img {
|
160 |
margin-right: 10px;
|
161 |
}
|
162 |
|
163 |
.custom-submit-button {
|
164 |
background-color: #E68369 !important;
|
|
|
165 |
border: none !important;
|
166 |
border-radius: 5px !important;
|
167 |
padding: 10px 20px !important;
|
|
|
226 |
def chat(user_input):
|
227 |
global chathistory, vectorstore
|
228 |
|
229 |
+
if not user_input.strip(): # Check if the input is empty or contains only whitespace
|
230 |
+
return gr.update(value='<span style="color:red;">الرجاء إدخال سؤال.</span>'), "", None
|
231 |
+
|
232 |
+
|
233 |
|
234 |
prompt = f"""
|
235 |
You are an expert Arabic-language assistant specialized in analyzing and responding to queries about Arabic PDF documents. Your responses should be precise, informative, and reflect the professional tone and structure expected in formal Arabic communication. Focus on extracting and presenting relevant information from the document clearly and systematically, while avoiding colloquial or informal language.
|
|
|
256 |
tts.save(audio_file)
|
257 |
|
258 |
history_display = [(msg["user_content"], msg["bot_content"]) for msg in chathistory]
|
259 |
+
return gr.update(value=''), history_display, audio_file
|
260 |
|
261 |
with gr.Blocks(css=custom_css) as demo:
|
262 |
with gr.Row():
|
|
|
270 |
submit_button_pdf = gr.Button("ارفع الملف", interactive=False)
|
271 |
with gr.Row():
|
272 |
with gr.Column(scale=3):
|
273 |
+
chatbot = gr.Chatbot(label="الشات", elem_classes="arabic-chatbox", height=400, rtl=True, layout='bubble', bubble_full_width=False)
|
274 |
|
275 |
with gr.Row():
|
276 |
chat_input = gr.Textbox(label="💬", rtl=True, visible=False, placeholder="أدخل سؤالك هنا ..", elem_id="inputbox", lines=2)
|
|
|
315 |
submit_button_pdf.click(process_pdf_and_enable_components, inputs=pdf_input, outputs=[output_label, submit_button_chat, submit_button_pdf, chatbot, chat_input, audio_output, clear_btn])
|
316 |
clear_btn.click(clear_chat, outputs=[chat_input, audio_output])
|
317 |
# Chat button connection
|
318 |
+
submit_button_chat.click(chat, inputs=chat_input, outputs=[output_label, chatbot, audio_output])
|
319 |
|
320 |
|
321 |
# Launch the Gradio app
|