SAVAI123 commited on
Commit
68a4514
·
verified ·
1 Parent(s): 2dfe51a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -37
app.py CHANGED
@@ -110,10 +110,10 @@ def rag_query(query, retriever):
110
  # Create context from retrieved documents
111
  context = "\n".join([doc.page_content for doc in docs])
112
  prompt = f"""Context:\n{context}
113
- Current Date: {current_date}
114
- Current Time: {current_time}
115
- Question: {query}
116
- Answer directly and concisely, using the current date and time information if relevant:"""
117
 
118
  response = llm.invoke(prompt)
119
  return response.content
@@ -165,72 +165,90 @@ def query_router(query, method, retriever):
165
  def reset_query_field():
166
  return "" # Reset only the query input
167
 
168
-
169
  # Function to update the clock
170
  def update_datetime():
171
  date, time = get_current_datetime()
172
  return date, time
173
 
 
 
 
 
 
 
 
174
  # Main function to create and launch the Gradio interface
175
  def main():
176
  # Initialize retriever
177
  print("Initializing retriever...")
178
  retriever = initialize_retriever()
179
 
180
-
181
-
182
- # Define custom CSS to style the logo across the entire header
183
  custom_css = """
184
- #header-container {
185
  width: 100%;
186
  background-color: black;
187
  padding: 15px 0;
188
  text-align: center;
189
  margin-bottom: 20px;
190
  }
191
-
192
 
193
-
194
- /* Hide the download button for images */
195
- #header-container .image-container .absolute {
 
 
 
 
 
 
 
 
 
196
  display: none !important;
197
  }
198
 
199
- /* Hide any download buttons and interactive elements in the header */
200
  #header-container button,
201
- #header-container .gr-button,
202
- #header-container .gr-panel {
203
  display: none !important;
204
  }
205
-
 
 
 
 
 
 
206
  """
207
 
208
- logo_path = "Equinix-LOGO.jpeg" # Make sure this file exists or update the path
209
 
210
  # Create Gradio UI
211
  with gr.Blocks(css=custom_css) as ui:
 
 
 
212
  # Header with logo
213
  with gr.Row(elem_id="header-container"):
214
- with gr.Column(scale=1):
215
- pass # Spacer
216
-
217
- with gr.Column(scale=2):
218
- # Option 1: Using gr.Image with interactive=False
219
- if os.path.exists(logo_path):
220
- gr.Image(value=logo_path, show_label=False, interactive=False, show_download_button=False)
 
 
221
  else:
222
- # Fallback to HTML method
223
  gr.HTML("""
224
- <div style="text-align:center; color:white; background-color:black; padding:20px;">
225
  <div style="color:#FF0000; font-size:24px;">■■■■</div>
226
- <div style="font-size:28px; letter-spacing:5px; margin-top:10px;">EQUINIX</div>
227
  </div>
228
  """)
229
 
230
- with gr.Column(scale=1):
231
- pass # Spacer
232
-
233
-
234
  # Title & Description
235
  gr.Markdown("<h1 style='text-align: center; color: black;'>Equinix Chatbot for Automation Team</h1>")
236
 
@@ -239,7 +257,7 @@ def main():
239
  date_display = gr.Textbox(label="Date", interactive=False)
240
  time_display = gr.Textbox(label="Time", interactive=False)
241
 
242
- # Update date and time using Gradio's interval functionality
243
  date_val, time_val = get_current_datetime()
244
  date_display.value = date_val
245
  time_display.value = time_val
@@ -255,7 +273,7 @@ def main():
255
  query_input = gr.Textbox(label="Enter your query")
256
  query_method = gr.Dropdown(["Team Query", "General Query"], label="Select Query Type", value="Team Query")
257
 
258
- # Output Textbox - Define it BEFORE you reference it in any callbacks
259
  output_box = gr.Textbox(label="Response", interactive=False)
260
 
261
  # Buttons Section
@@ -263,17 +281,17 @@ def main():
263
  submit_button = gr.Button("Submit")
264
  reset_button = gr.Button("Reset Query")
265
 
266
- # Button Click Events - Now output_box is defined before it's used in these callbacks
267
  submit_button.click(
268
  lambda query, method: query_router(query, method, retriever),
269
  inputs=[query_input, query_method],
270
  outputs=output_box
271
  )
272
 
273
- # Reset only the query input, not the dropdown
274
  reset_button.click(reset_query_field, inputs=[], outputs=[query_input])
275
 
276
- # This callback will update the date and time whenever the user submits a query
277
  submit_button.click(
278
  fn=update_datetime,
279
  inputs=[],
 
110
  # Create context from retrieved documents
111
  context = "\n".join([doc.page_content for doc in docs])
112
  prompt = f"""Context:\n{context}
113
+ Current Date: {current_date}
114
+ Current Time: {current_time}
115
+ Question: {query}
116
+ Answer directly and concisely, using the current date and time information if relevant:"""
117
 
118
  response = llm.invoke(prompt)
119
  return response.content
 
165
  def reset_query_field():
166
  return "" # Reset only the query input
167
 
 
168
  # Function to update the clock
169
  def update_datetime():
170
  date, time = get_current_datetime()
171
  return date, time
172
 
173
+ # Debug function to check logo file availability
174
+ def check_logo_file(logo_path):
175
+ print(f"Looking for logo at: {os.path.abspath(logo_path)}")
176
+ print(f"Logo file exists: {os.path.exists(logo_path)}")
177
+ print(f"Files in directory: {os.listdir()}")
178
+ return os.path.exists(logo_path)
179
+
180
  # Main function to create and launch the Gradio interface
181
  def main():
182
  # Initialize retriever
183
  print("Initializing retriever...")
184
  retriever = initialize_retriever()
185
 
186
+ # Define custom CSS to style the logo and header
 
 
187
  custom_css = """
188
+ #header-container {
189
  width: 100%;
190
  background-color: black;
191
  padding: 15px 0;
192
  text-align: center;
193
  margin-bottom: 20px;
194
  }
 
195
 
196
+ #logo-image {
197
+ max-height: 80px;
198
+ margin: 0 auto;
199
+ display: block;
200
+ }
201
+
202
+ /* Hide download buttons and controls */
203
+ #logo-wrapper .svelte-1b6r3t8 {
204
+ display: none !important;
205
+ }
206
+
207
+ .gradio-container .wrap.svelte-19hvt5v {
208
  display: none !important;
209
  }
210
 
211
+ /* Hide any interactive elements in the header */
212
  #header-container button,
213
+ #header-container .gr-button {
 
214
  display: none !important;
215
  }
216
+
217
+ /* Make date-time display more prominent */
218
+ .datetime-display input {
219
+ font-size: 16px;
220
+ text-align: center;
221
+ font-weight: bold;
222
+ }
223
  """
224
 
225
+ logo_path = "Equinix-LOGO.jpeg" # Make sure this file exists in the Space
226
 
227
  # Create Gradio UI
228
  with gr.Blocks(css=custom_css) as ui:
229
+ # Check if logo exists before creating UI
230
+ logo_exists = check_logo_file(logo_path)
231
+
232
  # Header with logo
233
  with gr.Row(elem_id="header-container"):
234
+ with gr.Column():
235
+ if logo_exists:
236
+ # Use HTML for more control over logo display
237
+ gr.HTML(f"""
238
+ <div style="text-align:center;">
239
+ <img id="logo-image" src="file/{logo_path}" alt="Equinix Logo"
240
+ style="max-height:80px; margin:0 auto; display:block;">
241
+ </div>
242
+ """)
243
  else:
244
+ # Fallback text-based logo
245
  gr.HTML("""
246
+ <div style="text-align:center; color:white; padding:10px;">
247
  <div style="color:#FF0000; font-size:24px;">■■■■</div>
248
+ <div style="font-size:28px; letter-spacing:5px; margin-top:5px;">EQUINIX</div>
249
  </div>
250
  """)
251
 
 
 
 
 
252
  # Title & Description
253
  gr.Markdown("<h1 style='text-align: center; color: black;'>Equinix Chatbot for Automation Team</h1>")
254
 
 
257
  date_display = gr.Textbox(label="Date", interactive=False)
258
  time_display = gr.Textbox(label="Time", interactive=False)
259
 
260
+ # Update date and time initially
261
  date_val, time_val = get_current_datetime()
262
  date_display.value = date_val
263
  time_display.value = time_val
 
273
  query_input = gr.Textbox(label="Enter your query")
274
  query_method = gr.Dropdown(["Team Query", "General Query"], label="Select Query Type", value="Team Query")
275
 
276
+ # Output Textbox
277
  output_box = gr.Textbox(label="Response", interactive=False)
278
 
279
  # Buttons Section
 
281
  submit_button = gr.Button("Submit")
282
  reset_button = gr.Button("Reset Query")
283
 
284
+ # Button Click Events
285
  submit_button.click(
286
  lambda query, method: query_router(query, method, retriever),
287
  inputs=[query_input, query_method],
288
  outputs=output_box
289
  )
290
 
291
+ # Reset only the query input
292
  reset_button.click(reset_query_field, inputs=[], outputs=[query_input])
293
 
294
+ # Update date and time on submission
295
  submit_button.click(
296
  fn=update_datetime,
297
  inputs=[],