MohammedNasser commited on
Commit
6db4a5e
·
verified ·
1 Parent(s): 45672e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -16
app.py CHANGED
@@ -146,23 +146,25 @@ label {
146
  color: #0C1844 !important;
147
  background-color: #FFF5E1;
148
  }
149
- .message.user {
150
- background-color: #ECFFE6;
 
 
 
 
 
151
  }
152
 
153
- .message.bot {
154
- background-color: #FFF6EA;
 
 
 
155
  }
156
 
157
- .message::before {
158
- content: '';
159
- display: inline-block;
160
- width: 24px;
161
- height: 24px;
162
- background-size: contain;
163
- background-repeat: no-repeat;
164
  margin-right: 10px;
165
- vertical-align: middle;
166
  }
167
 
168
  """
@@ -198,11 +200,11 @@ def upload_pdf(pdf_file):
198
  chain = create_chain(vectorstore)
199
  return "تم تحميل الملف بنجاح !", True
200
 
201
-
202
  def chat(user_input):
203
  global chain, chathistory
204
 
205
- chathistory.append({"role": "👤", "content": user_input})
206
 
207
  prompt = f"""
208
  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.
@@ -217,7 +219,9 @@ def chat(user_input):
217
  response = chain({"question": prompt})
218
  assistant_response = response["answer"]
219
 
220
- chathistory.append({"role": "🤖", "content": assistant_response})
 
 
221
  # Generate a unique identifier for the audio file
222
  audio_id = str(uuid.uuid4())
223
 
@@ -226,7 +230,7 @@ def chat(user_input):
226
  audio_file = f"{audio_id}.mp3"
227
  tts.save(audio_file)
228
 
229
- history_display = [(h["role"],h["content"]) for h in chathistory]
230
  return history_display, audio_file
231
 
232
  with gr.Blocks(css=custom_css) as demo:
 
146
  color: #0C1844 !important;
147
  background-color: #FFF5E1;
148
  }
149
+
150
+
151
+ #chatbox .message.user {
152
+ background-color: #f0f0f0; /* 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: #e0f7fa; /* Light cyan background for bot messages */
160
+ border-radius: 10px;
161
+ padding: 10px;
162
+ margin-bottom: 10px;
163
  }
164
 
165
+ #chatbox .message.user img,
166
+ #chatbox .message.bot img {
 
 
 
 
 
167
  margin-right: 10px;
 
168
  }
169
 
170
  """
 
200
  chain = create_chain(vectorstore)
201
  return "تم تحميل الملف بنجاح !", True
202
 
203
+
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.
 
219
  response = chain({"question": prompt})
220
  assistant_response = response["answer"]
221
 
222
+
223
+
224
+ chathistory.append({"role": "bot", "content": f"🤖 {assistant_response}"})
225
  # Generate a unique identifier for the audio file
226
  audio_id = str(uuid.uuid4())
227
 
 
230
  audio_file = f"{audio_id}.mp3"
231
  tts.save(audio_file)
232
 
233
+ history_display = [(msg["content"], msg["role"]) for msg in chathistory]
234
  return history_display, audio_file
235
 
236
  with gr.Blocks(css=custom_css) as demo: