Pijush2023 commited on
Commit
a5fe401
·
verified ·
1 Parent(s): f21d996

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +226 -9
app.py CHANGED
@@ -69,6 +69,84 @@ def get_current_time_and_date():
69
  # Example usage
70
  current_time_and_date = get_current_time_and_date()
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  def fetch_local_events():
73
  api_key = os.environ['SERP_API']
74
  url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Omaha&hl=en&gl=us&api_key={api_key}'
@@ -77,7 +155,7 @@ def fetch_local_events():
77
  if response.status_code == 200:
78
  events_results = response.json().get("events_results", [])
79
  events_html = """
80
- <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Events</h2>
81
  <style>
82
  .event-item {
83
  font-family: 'Verdana', sans-serif;
@@ -85,9 +163,7 @@ def fetch_local_events():
85
  background-color: #f0f8ff;
86
  margin-bottom: 15px;
87
  padding: 10px;
88
- border: 1px solid #ddd;
89
  border-radius: 5px;
90
- border: 2px solid red; /* Added red border */
91
  transition: box-shadow 0.3s ease, background-color 0.3s ease;
92
  font-weight: bold;
93
  }
@@ -148,6 +224,74 @@ def fetch_local_events():
148
  return "<p>Failed to fetch local events</p>"
149
 
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  def fetch_local_weather():
152
  try:
153
  api_key = os.environ['WEATHER_API']
@@ -169,7 +313,7 @@ def fetch_local_weather():
169
 
170
  weather_html = f"""
171
  <div class="weather-theme">
172
- <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Weather</h2>
173
  <div class="weather-content">
174
  <div class="weather-icon">
175
  <img src="https://www.weatherbit.io/static/img/icons/{get_weather_icon(condition)}.png" alt="{condition}" style="width: 100px; height: 100px;">
@@ -184,7 +328,6 @@ def fetch_local_weather():
184
  <style>
185
  .weather-theme {{
186
  animation: backgroundAnimation 10s infinite alternate;
187
- border: 2px solid red; /* Added red border */
188
  border-radius: 10px;
189
  padding: 10px;
190
  margin-bottom: 15px;
@@ -378,6 +521,81 @@ def generate_map(location_names):
378
  map_html = m._repr_html_()
379
  return map_html
380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
  def fetch_local_news():
382
  api_key = os.environ['SERP_API']
383
  url = f'https://serpapi.com/search.json?engine=google_news&q=omaha headline&api_key={api_key}'
@@ -385,7 +603,7 @@ def fetch_local_news():
385
  if response.status_code == 200:
386
  results = response.json().get("news_results", [])
387
  news_html = """
388
- <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Omaha Today Headlines</h2>
389
  <style>
390
  .news-item {
391
  font-family: 'Verdana', sans-serif;
@@ -393,7 +611,6 @@ def fetch_local_news():
393
  background-color: #f0f8ff;
394
  margin-bottom: 15px;
395
  padding: 10px;
396
- border: 2px solid red; /* Added red border */
397
  border-radius: 5px;
398
  transition: box-shadow 0.3s ease, background-color 0.3s ease;
399
  font-weight: bold;
@@ -575,7 +792,7 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
575
  chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
576
  choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
577
 
578
- gr.Markdown("<h1 style='color: red;'>Ask Radar !!!</h1>", elem_id="query-markdown")
579
  chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
580
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
581
  bot_msg = chat_msg.then(bot, [chatbot, choice], [chatbot, gr.Audio(interactive=False, autoplay=True)])
@@ -584,7 +801,7 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
584
  clear_button = gr.Button("Clear")
585
  clear_button.click(fn=clear_textbox, inputs=None, outputs=chat_input)
586
 
587
- gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
588
  audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy')
589
  audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="SAMLOne_real_time")
590
 
 
69
  # Example usage
70
  current_time_and_date = get_current_time_and_date()
71
 
72
+ # def fetch_local_events():
73
+ # api_key = os.environ['SERP_API']
74
+ # url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Omaha&hl=en&gl=us&api_key={api_key}'
75
+
76
+ # response = requests.get(url)
77
+ # if response.status_code == 200:
78
+ # events_results = response.json().get("events_results", [])
79
+ # events_html = """
80
+ # <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Events</h2>
81
+ # <style>
82
+ # .event-item {
83
+ # font-family: 'Verdana', sans-serif;
84
+ # color: #333;
85
+ # background-color: #f0f8ff;
86
+ # margin-bottom: 15px;
87
+ # padding: 10px;
88
+ # border: 1px solid #ddd;
89
+ # border-radius: 5px;
90
+ # border: 2px solid red; /* Added red border */
91
+ # transition: box-shadow 0.3s ease, background-color 0.3s ease;
92
+ # font-weight: bold;
93
+ # }
94
+ # .event-item:hover {
95
+ # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
96
+ # background-color: #e6f7ff;
97
+ # }
98
+ # .event-item a {
99
+ # color: #1E90FF;
100
+ # text-decoration: none;
101
+ # font-weight: bold;
102
+ # }
103
+ # .event-item a:hover {
104
+ # text-decoration: underline;
105
+ # }
106
+ # .event-preview {
107
+ # position: absolute;
108
+ # display: none;
109
+ # border: 1px solid #ccc;
110
+ # border-radius: 5px;
111
+ # box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
112
+ # background-color: white;
113
+ # z-index: 1000;
114
+ # max-width: 300px;
115
+ # padding: 10px;
116
+ # font-family: 'Verdana', sans-serif;
117
+ # color: #333;
118
+ # }
119
+ # </style>
120
+ # <script>
121
+ # function showPreview(event, previewContent) {
122
+ # var previewBox = document.getElementById('event-preview');
123
+ # previewBox.innerHTML = previewContent;
124
+ # previewBox.style.left = event.pageX + 'px';
125
+ # previewBox.style.top = event.pageY + 'px';
126
+ # previewBox.style.display = 'block';
127
+ # }
128
+ # function hidePreview() {
129
+ # var previewBox = document.getElementById('event-preview');
130
+ # previewBox.style.display = 'none';
131
+ # }
132
+ # </script>
133
+ # <div id="event-preview" class="event-preview"></div>
134
+ # """
135
+ # for index, event in enumerate(events_results):
136
+ # title = event.get("title", "No title")
137
+ # date = event.get("date", "No date")
138
+ # location = event.get("address", "No location")
139
+ # link = event.get("link", "#")
140
+ # events_html += f"""
141
+ # <div class="event-item" onmouseover="showPreview(event, 'Date: {date}<br>Location: {location}')" onmouseout="hidePreview()">
142
+ # <a href='{link}' target='_blank'>{index + 1}. {title}</a>
143
+ # <p>Date: {date}<br>Location: {location}</p>
144
+ # </div>
145
+ # """
146
+ # return events_html
147
+ # else:
148
+ # return "<p>Failed to fetch local events</p>"
149
+
150
  def fetch_local_events():
151
  api_key = os.environ['SERP_API']
152
  url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Omaha&hl=en&gl=us&api_key={api_key}'
 
155
  if response.status_code == 200:
156
  events_results = response.json().get("events_results", [])
157
  events_html = """
158
+ <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Events</h2>
159
  <style>
160
  .event-item {
161
  font-family: 'Verdana', sans-serif;
 
163
  background-color: #f0f8ff;
164
  margin-bottom: 15px;
165
  padding: 10px;
 
166
  border-radius: 5px;
 
167
  transition: box-shadow 0.3s ease, background-color 0.3s ease;
168
  font-weight: bold;
169
  }
 
224
  return "<p>Failed to fetch local events</p>"
225
 
226
 
227
+ # def fetch_local_weather():
228
+ # try:
229
+ # api_key = os.environ['WEATHER_API']
230
+ # url = f'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/omaha?unitGroup=metric&include=events%2Calerts%2Chours%2Cdays%2Ccurrent&key={api_key}'
231
+ # response = requests.get(url)
232
+ # response.raise_for_status()
233
+ # jsonData = response.json()
234
+
235
+ # current_conditions = jsonData.get("currentConditions", {})
236
+ # temp_celsius = current_conditions.get("temp", "N/A")
237
+
238
+ # if temp_celsius != "N/A":
239
+ # temp_fahrenheit = int((temp_celsius * 9/5) + 32)
240
+ # else:
241
+ # temp_fahrenheit = "N/A"
242
+
243
+ # condition = current_conditions.get("conditions", "N/A")
244
+ # humidity = current_conditions.get("humidity", "N/A")
245
+
246
+ # weather_html = f"""
247
+ # <div class="weather-theme">
248
+ # <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Weather</h2>
249
+ # <div class="weather-content">
250
+ # <div class="weather-icon">
251
+ # <img src="https://www.weatherbit.io/static/img/icons/{get_weather_icon(condition)}.png" alt="{condition}" style="width: 100px; height: 100px;">
252
+ # </div>
253
+ # <div class="weather-details">
254
+ # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Temperature: {temp_fahrenheit}°F</p>
255
+ # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Condition: {condition}</p>
256
+ # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Humidity: {humidity}%</p>
257
+ # </div>
258
+ # </div>
259
+ # </div>
260
+ # <style>
261
+ # .weather-theme {{
262
+ # animation: backgroundAnimation 10s infinite alternate;
263
+ # border: 2px solid red; /* Added red border */
264
+ # border-radius: 10px;
265
+ # padding: 10px;
266
+ # margin-bottom: 15px;
267
+ # background: linear-gradient(45deg, #ffcc33, #ff6666, #ffcc33, #ff6666);
268
+ # background-size: 400% 400%;
269
+ # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
270
+ # transition: box-shadow 0.3s ease, background-color 0.3s ease;
271
+ # }}
272
+ # .weather-theme:hover {{
273
+ # box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
274
+ # background-position: 100% 100%;
275
+ # }}
276
+ # @keyframes backgroundAnimation {{
277
+ # 0% {{ background-position: 0% 50%; }}
278
+ # 100% {{ background-position: 100% 50%; }}
279
+ # }}
280
+ # .weather-content {{
281
+ # display: flex;
282
+ # align-items: center;
283
+ # }}
284
+ # .weather-icon {{
285
+ # flex: 1;
286
+ # }}
287
+ # .weather-details {{
288
+ # flex: 3;
289
+ # }}
290
+ # </style>
291
+ # """
292
+ # return weather_html
293
+ # except requests.exceptions.RequestException as e:
294
+ # return f"<p>Failed to fetch local weather: {e}</p>"
295
  def fetch_local_weather():
296
  try:
297
  api_key = os.environ['WEATHER_API']
 
313
 
314
  weather_html = f"""
315
  <div class="weather-theme">
316
+ <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Weather</h2>
317
  <div class="weather-content">
318
  <div class="weather-icon">
319
  <img src="https://www.weatherbit.io/static/img/icons/{get_weather_icon(condition)}.png" alt="{condition}" style="width: 100px; height: 100px;">
 
328
  <style>
329
  .weather-theme {{
330
  animation: backgroundAnimation 10s infinite alternate;
 
331
  border-radius: 10px;
332
  padding: 10px;
333
  margin-bottom: 15px;
 
521
  map_html = m._repr_html_()
522
  return map_html
523
 
524
+ # def fetch_local_news():
525
+ # api_key = os.environ['SERP_API']
526
+ # url = f'https://serpapi.com/search.json?engine=google_news&q=omaha headline&api_key={api_key}'
527
+ # response = requests.get(url)
528
+ # if response.status_code == 200:
529
+ # results = response.json().get("news_results", [])
530
+ # news_html = """
531
+ # <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Omaha Today </h2>
532
+ # <style>
533
+ # .news-item {
534
+ # font-family: 'Verdana', sans-serif;
535
+ # color: #333;
536
+ # background-color: #f0f8ff;
537
+ # margin-bottom: 15px;
538
+ # padding: 10px;
539
+ # border: 2px solid red; /* Added red border */
540
+ # border-radius: 5px;
541
+ # transition: box-shadow 0.3s ease, background-color 0.3s ease;
542
+ # font-weight: bold;
543
+ # }
544
+ # .news-item:hover {
545
+ # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
546
+ # background-color: #e6f7ff;
547
+ # }
548
+ # .news-item a {
549
+ # color: #1E90FF;
550
+ # text-decoration: none;
551
+ # font-weight: bold;
552
+ # }
553
+ # .news-item a:hover {
554
+ # text-decoration: underline;
555
+ # }
556
+ # .news-preview {
557
+ # position: absolute;
558
+ # display: none;
559
+ # border: 1px solid #ccc;
560
+ # border-radius: 5px;
561
+ # box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
562
+ # background-color: white;
563
+ # z-index: 1000;
564
+ # max-width: 300px;
565
+ # padding: 10px;
566
+ # font-family: 'Verdana', sans-serif;
567
+ # color: #333;
568
+ # }
569
+ # </style>
570
+ # <script>
571
+ # function showPreview(event, previewContent) {
572
+ # var previewBox = document.getElementById('news-preview');
573
+ # previewBox.innerHTML = previewContent;
574
+ # previewBox.style.left = event.pageX + 'px';
575
+ # previewBox.style.top = event.pageY + 'px';
576
+ # previewBox.style.display = 'block';
577
+ # }
578
+ # function hidePreview() {
579
+ # var previewBox = document.getElementById('news-preview');
580
+ # previewBox.style.display = 'none';
581
+ # }
582
+ # </script>
583
+ # <div id="news-preview" class="news-preview"></div>
584
+ # """
585
+ # for index, result in enumerate(results[:7]):
586
+ # title = result.get("title", "No title")
587
+ # link = result.get("link", "#")
588
+ # snippet = result.get("snippet", "")
589
+ # news_html += f"""
590
+ # <div class="news-item" onmouseover="showPreview(event, '{snippet}')" onmouseout="hidePreview()">
591
+ # <a href='{link}' target='_blank'>{index + 1}. {title}</a>
592
+ # <p>{snippet}</p>
593
+ # </div>
594
+ # """
595
+ # return news_html
596
+ # else:
597
+ # return "<p>Failed to fetch local news</p>"
598
+
599
  def fetch_local_news():
600
  api_key = os.environ['SERP_API']
601
  url = f'https://serpapi.com/search.json?engine=google_news&q=omaha headline&api_key={api_key}'
 
603
  if response.status_code == 200:
604
  results = response.json().get("news_results", [])
605
  news_html = """
606
+ <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Omaha Today</h2>
607
  <style>
608
  .news-item {
609
  font-family: 'Verdana', sans-serif;
 
611
  background-color: #f0f8ff;
612
  margin-bottom: 15px;
613
  padding: 10px;
 
614
  border-radius: 5px;
615
  transition: box-shadow 0.3s ease, background-color 0.3s ease;
616
  font-weight: bold;
 
792
  chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
793
  choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
794
 
795
+ gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
796
  chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
797
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
798
  bot_msg = chat_msg.then(bot, [chatbot, choice], [chatbot, gr.Audio(interactive=False, autoplay=True)])
 
801
  clear_button = gr.Button("Clear")
802
  clear_button.click(fn=clear_textbox, inputs=None, outputs=chat_input)
803
 
804
+
805
  audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy')
806
  audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="SAMLOne_real_time")
807