prernajeet01 commited on
Commit
4909f6f
·
verified ·
1 Parent(s): 94bfddc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -9,6 +9,7 @@ from langchain.prompts import PromptTemplate
9
  from langchain.chains import LLMChain
10
  from datetime import datetime
11
  import pytz
 
12
 
13
  # Get API key from Hugging Face Spaces secrets
14
  google_api_key = os.environ.get("GOOGLE_API_KEY")
@@ -166,7 +167,7 @@ def query_router(query, method, retriever):
166
  # Function to update the clock
167
  def update_datetime():
168
  date, time = get_current_datetime()
169
- return f"{date}", f"{time}"
170
 
171
  # Main function to create and launch the Gradio interface
172
  def main():
@@ -212,6 +213,15 @@ def main():
212
  date_display = gr.Textbox(label="Date", interactive=False)
213
  time_display = gr.Textbox(label="Time", interactive=False)
214
 
 
 
 
 
 
 
 
 
 
215
  gr.Markdown("<p style='text-align: center; color: black;'>Ask me anything!</p>")
216
 
217
  # Input & Dropdown Section
@@ -225,20 +235,19 @@ def main():
225
  # Output Textbox
226
  output_box = gr.Textbox(label="Response", interactive=False)
227
 
228
- # Button Click Event
229
  submit_button.click(
230
  lambda query, method: query_router(query, method, retriever),
231
  inputs=[query_input, query_method],
232
  outputs=output_box
233
  )
234
 
235
- # Initialize date and time display
236
- date, time = get_current_datetime()
237
- date_display.value = date
238
- time_display.value = time
239
-
240
- # Update date and time every second
241
- ui.load(update_datetime, outputs=[date_display, time_display], every=1)
242
 
243
  # Launch UI
244
  ui.launch()
 
9
  from langchain.chains import LLMChain
10
  from datetime import datetime
11
  import pytz
12
+ import time
13
 
14
  # Get API key from Hugging Face Spaces secrets
15
  google_api_key = os.environ.get("GOOGLE_API_KEY")
 
167
  # Function to update the clock
168
  def update_datetime():
169
  date, time = get_current_datetime()
170
+ return date, time
171
 
172
  # Main function to create and launch the Gradio interface
173
  def main():
 
213
  date_display = gr.Textbox(label="Date", interactive=False)
214
  time_display = gr.Textbox(label="Time", interactive=False)
215
 
216
+ # Update date and time using Gradio's interval functionality
217
+ date_val, time_val = get_current_datetime()
218
+ date_display.value = date_val
219
+ time_display.value = time_val
220
+
221
+ # Add refresh button for time
222
+ refresh_btn = gr.Button("Update Date & Time")
223
+ refresh_btn.click(fn=update_datetime, inputs=[], outputs=[date_display, time_display])
224
+
225
  gr.Markdown("<p style='text-align: center; color: black;'>Ask me anything!</p>")
226
 
227
  # Input & Dropdown Section
 
235
  # Output Textbox
236
  output_box = gr.Textbox(label="Response", interactive=False)
237
 
238
+ # Button Click Events
239
  submit_button.click(
240
  lambda query, method: query_router(query, method, retriever),
241
  inputs=[query_input, query_method],
242
  outputs=output_box
243
  )
244
 
245
+ # This callback will update the date and time whenever the user submits a query
246
+ submit_button.click(
247
+ fn=update_datetime,
248
+ inputs=[],
249
+ outputs=[date_display, time_display]
250
+ )
 
251
 
252
  # Launch UI
253
  ui.launch()