Spaces:
Sleeping
Sleeping
MohammedNasser
commited on
Commit
•
6c6890f
1
Parent(s):
6db4a5e
Update app.py
Browse files
app.py
CHANGED
@@ -149,14 +149,14 @@ label {
|
|
149 |
|
150 |
|
151 |
#chatbox .message.user {
|
152 |
-
background-color: #
|
153 |
border-radius: 10px;
|
154 |
padding: 10px;
|
155 |
margin-bottom: 10px;
|
156 |
}
|
157 |
|
158 |
#chatbox .message.bot {
|
159 |
-
background-color: #
|
160 |
border-radius: 10px;
|
161 |
padding: 10px;
|
162 |
margin-bottom: 10px;
|
@@ -204,7 +204,6 @@ def upload_pdf(pdf_file):
|
|
204 |
def chat(user_input):
|
205 |
global chain, chathistory
|
206 |
|
207 |
-
chathistory.append({"role": "user", "content": f"👤 {user_input}"})
|
208 |
|
209 |
prompt = f"""
|
210 |
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.
|
@@ -212,8 +211,8 @@ def chat(user_input):
|
|
212 |
- Your answer directly reflects the content of the document.
|
213 |
- If the requested information is not available in the document, clearly state that in Arabic.
|
214 |
- Keep your response concise yet comprehensive, addressing the question fully.
|
215 |
-
- Always respond only in a professional and well-versed Arabic Language
|
216 |
-
Question: {user_input}
|
217 |
"""
|
218 |
|
219 |
response = chain({"question": prompt})
|
@@ -221,7 +220,7 @@ def chat(user_input):
|
|
221 |
|
222 |
|
223 |
|
224 |
-
chathistory.append({"
|
225 |
# Generate a unique identifier for the audio file
|
226 |
audio_id = str(uuid.uuid4())
|
227 |
|
@@ -230,7 +229,7 @@ def chat(user_input):
|
|
230 |
audio_file = f"{audio_id}.mp3"
|
231 |
tts.save(audio_file)
|
232 |
|
233 |
-
history_display = [(msg["
|
234 |
return history_display, audio_file
|
235 |
|
236 |
with gr.Blocks(css=custom_css) as demo:
|
@@ -245,7 +244,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
245 |
submit_button_pdf = gr.Button("ارفع الملف", interactive=False)
|
246 |
with gr.Row():
|
247 |
with gr.Column(scale=3):
|
248 |
-
chatbot = gr.Chatbot(label="الشات", elem_id="chatbox", height=400, rtl=True, layout='
|
249 |
|
250 |
with gr.Row():
|
251 |
chat_input = gr.Textbox(label="💬", rtl=True, visible=False, placeholder="أدخل سؤالك هنا ..", elem_id="inputbox", lines=2)
|
|
|
149 |
|
150 |
|
151 |
#chatbox .message.user {
|
152 |
+
background-color: #FFFBE6; /* Light gray background for user messages */
|
153 |
border-radius: 10px;
|
154 |
padding: 10px;
|
155 |
margin-bottom: 10px;
|
156 |
}
|
157 |
|
158 |
#chatbox .message.bot {
|
159 |
+
background-color: #E7FBE6; /* Light cyan background for bot messages */
|
160 |
border-radius: 10px;
|
161 |
padding: 10px;
|
162 |
margin-bottom: 10px;
|
|
|
204 |
def chat(user_input):
|
205 |
global chain, chathistory
|
206 |
|
|
|
207 |
|
208 |
prompt = f"""
|
209 |
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.
|
|
|
211 |
- Your answer directly reflects the content of the document.
|
212 |
- If the requested information is not available in the document, clearly state that in Arabic.
|
213 |
- Keep your response concise yet comprehensive, addressing the question fully.
|
214 |
+
- Always respond only in a professional and well-versed Arabic Language.
|
215 |
+
Question: {user_input}.
|
216 |
"""
|
217 |
|
218 |
response = chain({"question": prompt})
|
|
|
220 |
|
221 |
|
222 |
|
223 |
+
chathistory.append({"user_content": f"👤 {user_input}", "bot_content": f"🤖 {assistant_response}"})
|
224 |
# Generate a unique identifier for the audio file
|
225 |
audio_id = str(uuid.uuid4())
|
226 |
|
|
|
229 |
audio_file = f"{audio_id}.mp3"
|
230 |
tts.save(audio_file)
|
231 |
|
232 |
+
history_display = [(msg["user_content"], msg["bot_content"]) for msg in chathistory]
|
233 |
return history_display, audio_file
|
234 |
|
235 |
with gr.Blocks(css=custom_css) as demo:
|
|
|
244 |
submit_button_pdf = gr.Button("ارفع الملف", interactive=False)
|
245 |
with gr.Row():
|
246 |
with gr.Column(scale=3):
|
247 |
+
chatbot = gr.Chatbot(label="الشات", elem_id="chatbox", height=400, rtl=True, layout='bubble', bubble_full_width=False)
|
248 |
|
249 |
with gr.Row():
|
250 |
chat_input = gr.Textbox(label="💬", rtl=True, visible=False, placeholder="أدخل سؤالك هنا ..", elem_id="inputbox", lines=2)
|