Pijush2023 commited on
Commit
9711981
·
verified ·
1 Parent(s): 95c0119

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +335 -992
app.py CHANGED
@@ -1,882 +1,3 @@
1
- # import os
2
- # import re
3
- # import time
4
- # import requests
5
- # import logging
6
- # import folium
7
- # import gradio as gr
8
- # import tempfile
9
- # import torch
10
- # from datetime import datetime
11
- # import numpy as np
12
- # from gtts import gTTS
13
- # from googlemaps import Client as GoogleMapsClient
14
- # from diffusers import StableDiffusion3Pipeline
15
- # import concurrent.futures
16
- # from PIL import Image
17
-
18
- # from langchain_openai import OpenAIEmbeddings, ChatOpenAI
19
- # from langchain_pinecone import PineconeVectorStore
20
- # from langchain.prompts import PromptTemplate
21
- # from langchain.chains import RetrievalQA
22
- # from langchain.chains.conversation.memory import ConversationBufferWindowMemory
23
- # from langchain.agents import Tool, initialize_agent
24
- # from huggingface_hub import login
25
-
26
- # # Check if the token is already set in the environment variables
27
- # hf_token = os.getenv("HF_TOKEN")
28
-
29
- # if hf_token is None:
30
- # # If the token is not set, prompt for it (this should be done securely)
31
- # print("Please set your Hugging Face token in the environment variables.")
32
- # else:
33
- # # Login using the token
34
- # login(token=hf_token)
35
-
36
- # # Your application logic goes here
37
- # print("Logged in successfully to Hugging Face Hub!")
38
-
39
-
40
-
41
- # # Set up logging
42
- # logging.basicConfig(level=logging.DEBUG)
43
-
44
- # # Initialize OpenAI embeddings
45
- # embeddings = OpenAIEmbeddings(api_key=os.environ['OPENAI_API_KEY'])
46
-
47
- # # Initialize Pinecone
48
- # from pinecone import Pinecone
49
- # pc = Pinecone(api_key=os.environ['PINECONE_API_KEY'])
50
-
51
- # index_name = "omaha-details"
52
- # vectorstore = PineconeVectorStore(index_name=index_name, embedding=embeddings)
53
- # retriever = vectorstore.as_retriever(search_kwargs={'k': 5})
54
-
55
- # # Initialize ChatOpenAI model
56
- # chat_model = ChatOpenAI(api_key=os.environ['OPENAI_API_KEY'],
57
- # temperature=0, model='gpt-4o')
58
-
59
- # conversational_memory = ConversationBufferWindowMemory(
60
- # memory_key='chat_history',
61
- # k=10,
62
- # return_messages=True
63
- # )
64
-
65
- # def get_current_time_and_date():
66
- # now = datetime.now()
67
- # return now.strftime("%Y-%m-%d %H:%M:%S")
68
-
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}'
153
-
154
- # # response = requests.get(url)
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;
162
- # # color: #333;
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
- # # }
170
- # # .event-item:hover {
171
- # # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
172
- # # background-color: #e6f7ff;
173
- # # }
174
- # # .event-item a {
175
- # # color: #1E90FF;
176
- # # text-decoration: none;
177
- # # font-weight: bold;
178
- # # }
179
- # # .event-item a:hover {
180
- # # text-decoration: underline;
181
- # # }
182
- # # .event-preview {
183
- # # position: absolute;
184
- # # display: none;
185
- # # border: 1px solid #ccc;
186
- # # border-radius: 5px;
187
- # # box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
188
- # # background-color: white;
189
- # # z-index: 1000;
190
- # # max-width: 300px;
191
- # # padding: 10px;
192
- # # font-family: 'Verdana', sans-serif;
193
- # # color: #333;
194
- # # }
195
- # # </style>
196
- # # <script>
197
- # # function showPreview(event, previewContent) {
198
- # # var previewBox = document.getElementById('event-preview');
199
- # # previewBox.innerHTML = previewContent;
200
- # # previewBox.style.left = event.pageX + 'px';
201
- # # previewBox.style.top = event.pageY + 'px';
202
- # # previewBox.style.display = 'block';
203
- # # }
204
- # # function hidePreview() {
205
- # # var previewBox = document.getElementById('event-preview');
206
- # # previewBox.style.display = 'none';
207
- # # }
208
- # # </script>
209
- # # <div id="event-preview" class="event-preview"></div>
210
- # # """
211
- # # for index, event in enumerate(events_results):
212
- # # title = event.get("title", "No title")
213
- # # date = event.get("date", "No date")
214
- # # location = event.get("address", "No location")
215
- # # link = event.get("link", "#")
216
- # # events_html += f"""
217
- # # <div class="event-item" onmouseover="showPreview(event, 'Date: {date}<br>Location: {location}')" onmouseout="hidePreview()">
218
- # # <a href='{link}' target='_blank'>{index + 1}. {title}</a>
219
- # # <p>Date: {date}<br>Location: {location}</p>
220
- # # </div>
221
- # # """
222
- # # return events_html
223
- # # else:
224
- # # return "<p>Failed to fetch local events</p>"
225
-
226
- # def fetch_local_events():
227
- # api_key = os.environ['SERP_API']
228
- # url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Omaha&hl=en&gl=us&api_key={api_key}'
229
-
230
- # response = requests.get(url)
231
- # if response.status_code == 200:
232
- # events_results = response.json().get("events_results", [])
233
- # events_html = """
234
- # <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Events</h2>
235
- # <style>
236
- # .event-item {
237
- # font-family: 'Verdana', sans-serif;
238
- # color: #333;
239
- # margin-bottom: 15px;
240
- # padding: 10px;
241
- # font-weight: bold;
242
- # }
243
- # .event-item a {
244
- # color: #1E90FF;
245
- # text-decoration: none;
246
- # }
247
- # .event-item a:hover {
248
- # text-decoration: underline;
249
- # }
250
- # </style>
251
- # """
252
- # for index, event in enumerate(events_results):
253
- # title = event.get("title", "No title")
254
- # date = event.get("date", "No date")
255
- # location = event.get("address", "No location")
256
- # link = event.get("link", "#")
257
- # events_html += f"""
258
- # <div class="event-item">
259
- # <a href='{link}' target='_blank'>{index + 1}. {title}</a>
260
- # <p>Date: {date}<br>Location: {location}</p>
261
- # </div>
262
- # """
263
- # return events_html
264
- # else:
265
- # return "<p>Failed to fetch local events</p>"
266
-
267
-
268
- # # def fetch_local_weather():
269
- # # try:
270
- # # api_key = os.environ['WEATHER_API']
271
- # # url = f'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/omaha?unitGroup=metric&include=events%2Calerts%2Chours%2Cdays%2Ccurrent&key={api_key}'
272
- # # response = requests.get(url)
273
- # # response.raise_for_status()
274
- # # jsonData = response.json()
275
-
276
- # # current_conditions = jsonData.get("currentConditions", {})
277
- # # temp_celsius = current_conditions.get("temp", "N/A")
278
-
279
- # # if temp_celsius != "N/A":
280
- # # temp_fahrenheit = int((temp_celsius * 9/5) + 32)
281
- # # else:
282
- # # temp_fahrenheit = "N/A"
283
-
284
- # # condition = current_conditions.get("conditions", "N/A")
285
- # # humidity = current_conditions.get("humidity", "N/A")
286
-
287
- # # weather_html = f"""
288
- # # <div class="weather-theme">
289
- # # <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Weather</h2>
290
- # # <div class="weather-content">
291
- # # <div class="weather-icon">
292
- # # <img src="https://www.weatherbit.io/static/img/icons/{get_weather_icon(condition)}.png" alt="{condition}" style="width: 100px; height: 100px;">
293
- # # </div>
294
- # # <div class="weather-details">
295
- # # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Temperature: {temp_fahrenheit}°F</p>
296
- # # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Condition: {condition}</p>
297
- # # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Humidity: {humidity}%</p>
298
- # # </div>
299
- # # </div>
300
- # # </div>
301
- # # <style>
302
- # # .weather-theme {{
303
- # # animation: backgroundAnimation 10s infinite alternate;
304
- # # border: 2px solid red; /* Added red border */
305
- # # border-radius: 10px;
306
- # # padding: 10px;
307
- # # margin-bottom: 15px;
308
- # # background: linear-gradient(45deg, #ffcc33, #ff6666, #ffcc33, #ff6666);
309
- # # background-size: 400% 400%;
310
- # # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
311
- # # transition: box-shadow 0.3s ease, background-color 0.3s ease;
312
- # # }}
313
- # # .weather-theme:hover {{
314
- # # box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
315
- # # background-position: 100% 100%;
316
- # # }}
317
- # # @keyframes backgroundAnimation {{
318
- # # 0% {{ background-position: 0% 50%; }}
319
- # # 100% {{ background-position: 100% 50%; }}
320
- # # }}
321
- # # .weather-content {{
322
- # # display: flex;
323
- # # align-items: center;
324
- # # }}
325
- # # .weather-icon {{
326
- # # flex: 1;
327
- # # }}
328
- # # .weather-details {{
329
- # # flex: 3;
330
- # # }}
331
- # # </style>
332
- # # """
333
- # # return weather_html
334
- # # except requests.exceptions.RequestException as e:
335
- # # return f"<p>Failed to fetch local weather: {e}</p>"
336
- # def fetch_local_weather():
337
- # try:
338
- # api_key = os.environ['WEATHER_API']
339
- # url = f'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/omaha?unitGroup=metric&include=events%2Calerts%2Chours%2Cdays%2Ccurrent&key={api_key}'
340
- # response = requests.get(url)
341
- # response.raise_for_status()
342
- # jsonData = response.json()
343
-
344
- # current_conditions = jsonData.get("currentConditions", {})
345
- # temp_celsius = current_conditions.get("temp", "N/A")
346
-
347
- # if temp_celsius != "N/A":
348
- # temp_fahrenheit = int((temp_celsius * 9/5) + 32)
349
- # else:
350
- # temp_fahrenheit = "N/A"
351
-
352
- # condition = current_conditions.get("conditions", "N/A")
353
- # humidity = current_conditions.get("humidity", "N/A")
354
-
355
- # weather_html = f"""
356
- # <div class="weather-theme">
357
- # <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Weather</h2>
358
- # <div class="weather-content">
359
- # <div class="weather-icon">
360
- # <img src="https://www.weatherbit.io/static/img/icons/{get_weather_icon(condition)}.png" alt="{condition}" style="width: 100px; height: 100px;">
361
- # </div>
362
- # <div class="weather-details">
363
- # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Temperature: {temp_fahrenheit}°F</p>
364
- # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Condition: {condition}</p>
365
- # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Humidity: {humidity}%</p>
366
- # </div>
367
- # </div>
368
- # </div>
369
- # <style>
370
- # .weather-theme {{
371
- # animation: backgroundAnimation 10s infinite alternate;
372
- # border-radius: 10px;
373
- # padding: 10px;
374
- # margin-bottom: 15px;
375
- # background: linear-gradient(45deg, #ffcc33, #ff6666, #ffcc33, #ff6666);
376
- # background-size: 400% 400%;
377
- # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
378
- # transition: box-shadow 0.3s ease, background-color 0.3s ease;
379
- # }}
380
- # .weather-theme:hover {{
381
- # box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
382
- # background-position: 100% 100%;
383
- # }}
384
- # @keyframes backgroundAnimation {{
385
- # 0% {{ background-position: 0% 50%; }}
386
- # 100% {{ background-position: 100% 50%; }}
387
- # }}
388
- # .weather-content {{
389
- # display: flex;
390
- # align-items: center;
391
- # }}
392
- # .weather-icon {{
393
- # flex: 1;
394
- # }}
395
- # .weather-details {{
396
- # flex: 3;
397
- # }}
398
- # </style>
399
- # """
400
- # return weather_html
401
- # except requests.exceptions.RequestException as e:
402
- # return f"<p>Failed to fetch local weather: {e}</p>"
403
-
404
- # def get_weather_icon(condition):
405
- # condition_map = {
406
- # "Clear": "c01d",
407
- # "Partly Cloudy": "c02d",
408
- # "Cloudy": "c03d",
409
- # "Overcast": "c04d",
410
- # "Mist": "a01d",
411
- # "Patchy rain possible": "r01d",
412
- # "Light rain": "r02d",
413
- # "Moderate rain": "r03d",
414
- # "Heavy rain": "r04d",
415
- # "Snow": "s01d",
416
- # "Thunderstorm": "t01d",
417
- # "Fog": "a05d",
418
- # }
419
- # return condition_map.get(condition, "c04d")
420
-
421
- # # Update prompt templates to include fetched details
422
-
423
- # current_time_and_date = get_current_time_and_date()
424
-
425
-
426
-
427
- # # Define prompt templates
428
- # template1 = """You are an expert concierge who is helpful and a renowned guide for Omaha, Nebraska. Based on weather being a sunny bright day and the today's date is 20th june 2024, use the following pieces of context,
429
- # memory, and message history, along with your knowledge of perennial events in Omaha, Nebraska, to answer the question at the end. If you don't know the answer, just say "Homie, I need to get more data for this," and don't try to make up an answer.
430
- # Use fifteen sentences maximum. Keep the answer as detailed as possible. Always include the address, time, date, and
431
- # event type and description. Always say "It was my pleasure!" at the end of the answer.
432
- # {context}
433
- # Question: {question}
434
- # Helpful Answer:"""
435
-
436
- # template2 = """You are an expert concierge who is helpful and a renowned guide for Omaha, Nebraska. Based on today's weather being a sunny bright day and today's date is 20th june 2024, take the location or address but don't show the location or address on the output prompts. Use the following pieces of context,
437
- # memory, and message history, along with your knowledge of perennial events in Omaha, Nebraska, to answer the question at the end. If you don't know the answer, just say "Homie, I need to get more data for this," and don't try to make up an answer.
438
- # Keep the answer short and sweet and crisp. Always say "It was my pleasure!" at the end of the answer.
439
- # {context}
440
- # Question: {question}
441
- # Helpful Answer:"""
442
-
443
-
444
-
445
- # QA_CHAIN_PROMPT_1 = PromptTemplate(input_variables=["context", "question"], template=template1)
446
- # QA_CHAIN_PROMPT_2 = PromptTemplate(input_variables=["context", "question"], template=template2)
447
-
448
-
449
- # # Define the retrieval QA chain
450
- # def build_qa_chain(prompt_template):
451
- # qa_chain = RetrievalQA.from_chain_type(
452
- # llm=chat_model,
453
- # chain_type="stuff",
454
- # retriever=retriever,
455
- # chain_type_kwargs={"prompt": prompt_template}
456
- # )
457
- # tools = [
458
- # Tool(
459
- # name='Knowledge Base',
460
- # func=qa_chain,
461
- # description='Use this tool when answering general knowledge queries to get more information about the topic'
462
- # )
463
- # ]
464
- # return qa_chain, tools
465
-
466
- # # Define the agent initializer
467
- # def initialize_agent_with_prompt(prompt_template):
468
- # qa_chain, tools = build_qa_chain(prompt_template)
469
- # agent = initialize_agent(
470
- # agent='chat-conversational-react-description',
471
- # tools=tools,
472
- # llm=chat_model,
473
- # verbose=False,
474
- # max_iteration=5,
475
- # early_stopping_method='generate',
476
- # memory=conversational_memory
477
- # )
478
- # return agent
479
-
480
- # # Define the function to generate answers
481
- # def generate_answer(message, choice):
482
- # logging.debug(f"generate_answer called with prompt_choice: {choice}")
483
-
484
- # if choice == "Details":
485
- # agent = initialize_agent_with_prompt(QA_CHAIN_PROMPT_1)
486
- # elif choice == "Conversational":
487
- # agent = initialize_agent_with_prompt(QA_CHAIN_PROMPT_2)
488
- # else:
489
- # logging.error(f"Invalid prompt_choice: {choice}. Defaulting to 'Conversational'")
490
- # agent = initialize_agent_with_prompt(QA_CHAIN_PROMPT_2)
491
- # response = agent(message)
492
-
493
- # # Extract addresses for mapping regardless of the choice
494
- # addresses = extract_addresses(response['output'])
495
- # return response['output'], addresses
496
-
497
-
498
-
499
- # def bot(history, choice):
500
- # if not history:
501
- # return history
502
- # response, addresses = generate_answer(history[-1][0], choice)
503
- # history[-1][1] = ""
504
-
505
- # # Generate audio for the entire response in a separate thread
506
- # with concurrent.futures.ThreadPoolExecutor() as executor:
507
- # audio_future = executor.submit(generate_audio_elevenlabs, response)
508
-
509
- # for character in response:
510
- # history[-1][1] += character
511
- # time.sleep(0.05) # Adjust the speed of text appearance
512
- # yield history, None
513
-
514
- # audio_path = audio_future.result()
515
- # yield history, audio_path
516
-
517
-
518
- # def add_message(history, message):
519
- # history.append((message, None))
520
- # return history, gr.Textbox(value="", interactive=True, placeholder="Enter message or upload file...", show_label=False)
521
-
522
- # def print_like_dislike(x: gr.LikeData):
523
- # print(x.index, x.value, x.liked)
524
-
525
- # def extract_addresses(response):
526
- # if not isinstance(response, str):
527
- # response = str(response)
528
- # address_patterns = [
529
- # r'([A-Z].*,\sOmaha,\sNE\s\d{5})',
530
- # r'(\d{4}\s.*,\sOmaha,\sNE\s\d{5})',
531
- # r'([A-Z].*,\sNE\s\d{5})',
532
- # r'([A-Z].*,.*\sSt,\sOmaha,\sNE\s\d{5})',
533
- # r'([A-Z].*,.*\sStreets,\sOmaha,\sNE\s\d{5})',
534
- # r'(\d{2}.*\sStreets)',
535
- # r'([A-Z].*\s\d{2},\sOmaha,\sNE\s\d{5})'
536
- # ]
537
- # addresses = []
538
- # for pattern in address_patterns:
539
- # addresses.extend(re.findall(pattern, response))
540
- # return addresses
541
-
542
- # all_addresses = []
543
-
544
- # def generate_map(location_names):
545
- # global all_addresses
546
- # all_addresses.extend(location_names)
547
-
548
- # api_key = os.environ['GOOGLEMAPS_API_KEY']
549
- # gmaps = GoogleMapsClient(key=api_key)
550
-
551
- # m = folium.Map(location=[41.2565, -95.9345], zoom_start=12)
552
-
553
- # for location_name in all_addresses:
554
- # geocode_result = gmaps.geocode(location_name)
555
- # if geocode_result:
556
- # location = geocode_result[0]['geometry']['location']
557
- # folium.Marker(
558
- # [location['lat'], location['lng']],
559
- # tooltip=f"{geocode_result[0]['formatted_address']}"
560
- # ).add_to(m)
561
-
562
- # map_html = m._repr_html_()
563
- # return map_html
564
-
565
- # # def fetch_local_news():
566
- # # api_key = os.environ['SERP_API']
567
- # # url = f'https://serpapi.com/search.json?engine=google_news&q=omaha headline&api_key={api_key}'
568
- # # response = requests.get(url)
569
- # # if response.status_code == 200:
570
- # # results = response.json().get("news_results", [])
571
- # # news_html = """
572
- # # <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Omaha Today </h2>
573
- # # <style>
574
- # # .news-item {
575
- # # font-family: 'Verdana', sans-serif;
576
- # # color: #333;
577
- # # background-color: #f0f8ff;
578
- # # margin-bottom: 15px;
579
- # # padding: 10px;
580
- # # border: 2px solid red; /* Added red border */
581
- # # border-radius: 5px;
582
- # # transition: box-shadow 0.3s ease, background-color 0.3s ease;
583
- # # font-weight: bold;
584
- # # }
585
- # # .news-item:hover {
586
- # # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
587
- # # background-color: #e6f7ff;
588
- # # }
589
- # # .news-item a {
590
- # # color: #1E90FF;
591
- # # text-decoration: none;
592
- # # font-weight: bold;
593
- # # }
594
- # # .news-item a:hover {
595
- # # text-decoration: underline;
596
- # # }
597
- # # .news-preview {
598
- # # position: absolute;
599
- # # display: none;
600
- # # border: 1px solid #ccc;
601
- # # border-radius: 5px;
602
- # # box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
603
- # # background-color: white;
604
- # # z-index: 1000;
605
- # # max-width: 300px;
606
- # # padding: 10px;
607
- # # font-family: 'Verdana', sans-serif;
608
- # # color: #333;
609
- # # }
610
- # # </style>
611
- # # <script>
612
- # # function showPreview(event, previewContent) {
613
- # # var previewBox = document.getElementById('news-preview');
614
- # # previewBox.innerHTML = previewContent;
615
- # # previewBox.style.left = event.pageX + 'px';
616
- # # previewBox.style.top = event.pageY + 'px';
617
- # # previewBox.style.display = 'block';
618
- # # }
619
- # # function hidePreview() {
620
- # # var previewBox = document.getElementById('news-preview');
621
- # # previewBox.style.display = 'none';
622
- # # }
623
- # # </script>
624
- # # <div id="news-preview" class="news-preview"></div>
625
- # # """
626
- # # for index, result in enumerate(results[:7]):
627
- # # title = result.get("title", "No title")
628
- # # link = result.get("link", "#")
629
- # # snippet = result.get("snippet", "")
630
- # # news_html += f"""
631
- # # <div class="news-item" onmouseover="showPreview(event, '{snippet}')" onmouseout="hidePreview()">
632
- # # <a href='{link}' target='_blank'>{index + 1}. {title}</a>
633
- # # <p>{snippet}</p>
634
- # # </div>
635
- # # """
636
- # # return news_html
637
- # # else:
638
- # # return "<p>Failed to fetch local news</p>"
639
-
640
- # def fetch_local_news():
641
- # api_key = os.environ['SERP_API']
642
- # url = f'https://serpapi.com/search.json?engine=google_news&q=omaha headline&api_key={api_key}'
643
- # response = requests.get(url)
644
- # if response.status_code == 200:
645
- # results = response.json().get("news_results", [])
646
- # news_html = """
647
- # <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Omaha Today</h2>
648
- # <style>
649
- # .news-item {
650
- # font-family: 'Verdana', sans-serif;
651
- # color: #333;
652
- # background-color: #f0f8ff;
653
- # margin-bottom: 15px;
654
- # padding: 10px;
655
- # border-radius: 5px;
656
- # transition: box-shadow 0.3s ease, background-color 0.3s ease;
657
- # font-weight: bold;
658
- # }
659
- # .news-item:hover {
660
- # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
661
- # background-color: #e6f7ff;
662
- # }
663
- # .news-item a {
664
- # color: #1E90FF;
665
- # text-decoration: none;
666
- # font-weight: bold;
667
- # }
668
- # .news-item a:hover {
669
- # text-decoration: underline;
670
- # }
671
- # .news-preview {
672
- # position: absolute;
673
- # display: none;
674
- # border: 1px solid #ccc;
675
- # border-radius: 5px;
676
- # box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
677
- # background-color: white;
678
- # z-index: 1000;
679
- # max-width: 300px;
680
- # padding: 10px;
681
- # font-family: 'Verdana', sans-serif;
682
- # color: #333;
683
- # }
684
- # </style>
685
- # <script>
686
- # function showPreview(event, previewContent) {
687
- # var previewBox = document.getElementById('news-preview');
688
- # previewBox.innerHTML = previewContent;
689
- # previewBox.style.left = event.pageX + 'px';
690
- # previewBox.style.top = event.pageY + 'px';
691
- # previewBox.style.display = 'block';
692
- # }
693
- # function hidePreview() {
694
- # var previewBox = document.getElementById('news-preview');
695
- # previewBox.style.display = 'none';
696
- # }
697
- # </script>
698
- # <div id="news-preview" class="news-preview"></div>
699
- # """
700
- # for index, result in enumerate(results[:7]):
701
- # title = result.get("title", "No title")
702
- # link = result.get("link", "#")
703
- # snippet = result.get("snippet", "")
704
- # news_html += f"""
705
- # <div class="news-item" onmouseover="showPreview(event, '{snippet}')" onmouseout="hidePreview()">
706
- # <a href='{link}' target='_blank'>{index + 1}. {title}</a>
707
- # <p>{snippet}</p>
708
- # </div>
709
- # """
710
- # return news_html
711
- # else:
712
- # return "<p>Failed to fetch local news</p>"
713
-
714
-
715
- # # Voice Control
716
- # import numpy as np
717
- # import torch
718
- # from transformers import pipeline, AutoModelForSpeechSeq2Seq, AutoProcessor
719
-
720
- # model_id = 'openai/whisper-large-v3'
721
- # device = "cuda:0" if torch.cuda.is_available() else "cpu"
722
- # torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
723
- # model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype,
724
- # #low_cpu_mem_usage=True,
725
- # use_safetensors=True).to(device)
726
- # processor = AutoProcessor.from_pretrained(model_id)
727
-
728
- # # Optimized ASR pipeline
729
- # pipe_asr = pipeline("automatic-speech-recognition", model=model, tokenizer=processor.tokenizer, feature_extractor=processor.feature_extractor, max_new_tokens=128, chunk_length_s=15, batch_size=16, torch_dtype=torch_dtype, device=device, return_timestamps=True)
730
-
731
- # base_audio_drive = "/data/audio"
732
-
733
- # import numpy as np
734
-
735
- # def transcribe_function(stream, new_chunk):
736
- # try:
737
- # sr, y = new_chunk[0], new_chunk[1]
738
- # except TypeError:
739
- # print(f"Error chunk structure: {type(new_chunk)}, content: {new_chunk}")
740
- # return stream, "", None
741
-
742
- # y = y.astype(np.float32) / np.max(np.abs(y))
743
-
744
- # if stream is not None:
745
- # stream = np.concatenate([stream, y])
746
- # else:
747
- # stream = y
748
-
749
- # result = pipe_asr({"array": stream, "sampling_rate": sr}, return_timestamps=False)
750
-
751
- # full_text = result.get("text", "")
752
-
753
- # return stream, full_text, result
754
-
755
-
756
- # def update_map_with_response(history):
757
- # if not history:
758
- # return ""
759
- # response = history[-1][1]
760
- # addresses = extract_addresses(response)
761
- # return generate_map(addresses)
762
-
763
-
764
-
765
- # def clear_textbox():
766
- # return ""
767
-
768
- # def show_map_if_details(history,choice):
769
- # if choice in ["Details", "Conversational"]:
770
- # return gr.update(visible=True), update_map_with_response(history)
771
- # else:
772
- # return gr.update(visible(False), "")
773
-
774
-
775
-
776
- # def generate_audio_elevenlabs(text):
777
- # XI_API_KEY = os.environ['ELEVENLABS_API']
778
- # VOICE_ID = 'd9MIrwLnvDeH7aZb61E9' # Replace with your voice ID
779
- # tts_url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}/stream"
780
- # headers = {
781
- # "Accept": "application/json",
782
- # "xi-api-key": XI_API_KEY
783
- # }
784
- # data = {
785
- # "text": str(text),
786
- # "model_id": "eleven_multilingual_v2",
787
- # "voice_settings": {
788
- # "stability": 1.0,
789
- # "similarity_boost": 0.0,
790
- # "style": 0.60, # Adjust style for more romantic tone
791
- # "use_speaker_boost": False
792
- # }
793
- # }
794
- # response = requests.post(tts_url, headers=headers, json=data, stream=True)
795
- # if response.ok:
796
- # with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
797
- # for chunk in response.iter_content(chunk_size=1024):
798
- # f.write(chunk)
799
- # temp_audio_path = f.name
800
- # logging.debug(f"Audio saved to {temp_audio_path}")
801
- # return temp_audio_path
802
- # else:
803
- # logging.error(f"Error generating audio: {response.text}")
804
- # return None
805
-
806
- # # Stable Diffusion setup
807
- # pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", torch_dtype=torch.float16)
808
- # pipe = pipe.to("cuda")
809
-
810
- # def generate_image(prompt):
811
- # image = pipe(
812
- # prompt,
813
- # negative_prompt="",
814
- # num_inference_steps=28,
815
- # guidance_scale=3.0,
816
- # ).images[0]
817
- # return image
818
-
819
- # # Hardcoded prompt for image generation
820
- # # hardcoded_prompt_1 = "Useing The top events like 'Summer Art Festival'and Date - 06/19/2024 ,Weather-Sunny Bright Day.Create Highly Visually Compelling High Resolution and High Quality Photographics Advatizement for 'Toyota'"
821
- # hardcoded_prompt_1="Give a high quality photograph of a great looking red 2026 toyota coupe against a skyline setting in th night, michael mann style in omaha enticing the consumer to buy this product"
822
- # # hardcoded_prompt_2 = "Create a vibrant poster of Nebraska with beautiful weather, featuring picturesque landscapes, clear skies, and the word 'Nebraska' prominently displayed."
823
- # hardcoded_prompt_2="A vibrant and dynamic football game scene in the style of Peter Paul Rubens, showcasing the intense match between Alabama and Nebraska. The players are depicted with the dramatic, muscular physiques and expressive faces typical of Rubens' style. The Alabama team is wearing their iconic crimson and white uniforms, while the Nebraska team is in their classic red and white attire. The scene is filled with action, with players in mid-motion, tackling, running, and catching the ball. The background features a grand stadium filled with cheering fans, banners, and the natural landscape in the distance. The colors are rich and vibrant, with a strong use of light and shadow to create depth and drama. The overall atmosphere captures the intensity and excitement of the game, infused with the grandeur and dynamism characteristic of Rubens' work."
824
- # hardcoded_prompt_3 = "Create a high-energy scene of a DJ performing on a large stage with vibrant lights, colorful lasers, a lively dancing crowd, and various electronic equipment in the background."
825
-
826
-
827
- # def update_images():
828
- # image_1 = generate_image(hardcoded_prompt_1)
829
- # image_2 = generate_image(hardcoded_prompt_2)
830
- # image_3 = generate_image(hardcoded_prompt_3)
831
- # return image_1, image_2, image_3
832
-
833
- # with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
834
-
835
- # with gr.Row():
836
- # with gr.Column():
837
- # state = gr.State()
838
-
839
- # chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
840
- # choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
841
-
842
- # gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
843
- # chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
844
- # chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
845
- # bot_msg = chat_msg.then(bot, [chatbot, choice], [chatbot, gr.Audio(interactive=False, autoplay=True)])
846
- # bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
847
- # chatbot.like(print_like_dislike, None, None)
848
- # clear_button = gr.Button("Clear")
849
- # clear_button.click(fn=clear_textbox, inputs=None, outputs=chat_input)
850
-
851
-
852
- # audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy')
853
- # audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="SAMLOne_real_time")
854
-
855
- # gr.Markdown("<h1 style='color: red;'>Map</h1>", elem_id="location-markdown")
856
- # location_output = gr.HTML()
857
- # bot_msg.then(show_map_if_details, [chatbot, choice], [location_output, location_output])
858
-
859
- # with gr.Column():
860
- # weather_output = gr.HTML(value=fetch_local_weather())
861
- # news_output = gr.HTML(value=fetch_local_news())
862
- # news_output = gr.HTML(value=fetch_local_events())
863
-
864
- # with gr.Column():
865
-
866
- # image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
867
- # image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
868
- # image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
869
-
870
-
871
- # refresh_button = gr.Button("Refresh Images")
872
- # refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
873
-
874
- # demo.queue()
875
- # demo.launch(share=True)
876
-
877
-
878
-
879
-
880
  import os
881
  import re
882
  import time
@@ -902,9 +23,6 @@ from langchain.chains.conversation.memory import ConversationBufferWindowMemory
902
  from langchain.agents import Tool, initialize_agent
903
  from huggingface_hub import login
904
 
905
- import sqlite3
906
- from passlib.hash import bcrypt # Ensure passlib is installed: pip install passlib
907
-
908
  # Check if the token is already set in the environment variables
909
  hf_token = os.getenv("HF_TOKEN")
910
 
@@ -918,6 +36,8 @@ else:
918
  # Your application logic goes here
919
  print("Logged in successfully to Hugging Face Hub!")
920
 
 
 
921
  # Set up logging
922
  logging.basicConfig(level=logging.DEBUG)
923
 
@@ -942,19 +62,173 @@ conversational_memory = ConversationBufferWindowMemory(
942
  return_messages=True
943
  )
944
 
945
- def get_current_time_and_date():
946
- now = datetime.now()
947
- return now.strftime("%Y-%m-%d %H:%M:%S")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
948
 
949
- # Example usage
950
- current_time_and_date = get_current_time_and_date()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
951
 
952
  def fetch_local_events():
953
  api_key = os.environ['SERP_API']
954
  url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Omaha&hl=en&gl=us&api_key={api_key}'
955
 
956
  response = requests.get(url)
957
- if response.status_code == 200 {
958
  events_results = response.json().get("events_results", [])
959
  events_html = """
960
  <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Events</h2>
@@ -990,6 +264,75 @@ def fetch_local_events():
990
  else:
991
  return "<p>Failed to fetch local events</p>"
992
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
993
  def fetch_local_weather():
994
  try:
995
  api_key = os.environ['WEATHER_API']
@@ -1075,8 +418,12 @@ def get_weather_icon(condition):
1075
  }
1076
  return condition_map.get(condition, "c04d")
1077
 
 
 
1078
  current_time_and_date = get_current_time_and_date()
1079
 
 
 
1080
  # Define prompt templates
1081
  template1 = """You are an expert concierge who is helpful and a renowned guide for Omaha, Nebraska. Based on weather being a sunny bright day and the today's date is 20th june 2024, use the following pieces of context,
1082
  memory, and message history, along with your knowledge of perennial events in Omaha, Nebraska, to answer the question at the end. If you don't know the answer, just say "Homie, I need to get more data for this," and don't try to make up an answer.
@@ -1093,9 +440,12 @@ Keep the answer short and sweet and crisp. Always say "It was my pleasure!" at t
1093
  Question: {question}
1094
  Helpful Answer:"""
1095
 
 
 
1096
  QA_CHAIN_PROMPT_1 = PromptTemplate(input_variables=["context", "question"], template=template1)
1097
  QA_CHAIN_PROMPT_2 = PromptTemplate(input_variables=["context", "question"], template=template2)
1098
 
 
1099
  # Define the retrieval QA chain
1100
  def build_qa_chain(prompt_template):
1101
  qa_chain = RetrievalQA.from_chain_type(
@@ -1143,6 +493,8 @@ def generate_answer(message, choice):
1143
  # Extract addresses for mapping regardless of the choice
1144
  addresses = extract_addresses(response['output'])
1145
  return response['output'], addresses
 
 
1146
 
1147
  def bot(history, choice):
1148
  if not history:
@@ -1162,6 +514,7 @@ def bot(history, choice):
1162
  audio_path = audio_future.result()
1163
  yield history, audio_path
1164
 
 
1165
  def add_message(history, message):
1166
  history.append((message, None))
1167
  return history, gr.Textbox(value="", interactive=True, placeholder="Enter message or upload file...", show_label=False)
@@ -1209,11 +562,86 @@ def generate_map(location_names):
1209
  map_html = m._repr_html_()
1210
  return map_html
1211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1212
  def fetch_local_news():
1213
  api_key = os.environ['SERP_API']
1214
  url = f'https://serpapi.com/search.json?engine=google_news&q=omaha headline&api_key={api_key}'
1215
  response = requests.get(url)
1216
- if response.status_code == 200 {
1217
  results = response.json().get("news_results", [])
1218
  news_html = """
1219
  <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Omaha Today</h2>
@@ -1283,6 +711,7 @@ def fetch_local_news():
1283
  else:
1284
  return "<p>Failed to fetch local news</p>"
1285
 
 
1286
  # Voice Control
1287
  import numpy as np
1288
  import torch
@@ -1301,6 +730,8 @@ pipe_asr = pipeline("automatic-speech-recognition", model=model, tokenizer=proce
1301
 
1302
  base_audio_drive = "/data/audio"
1303
 
 
 
1304
  def transcribe_function(stream, new_chunk):
1305
  try:
1306
  sr, y = new_chunk[0], new_chunk[1]
@@ -1320,6 +751,7 @@ def transcribe_function(stream, new_chunk):
1320
  full_text = result.get("text", "")
1321
 
1322
  return stream, full_text, result
 
1323
 
1324
  def update_map_with_response(history):
1325
  if not history:
@@ -1328,6 +760,8 @@ def update_map_with_response(history):
1328
  addresses = extract_addresses(response)
1329
  return generate_map(addresses)
1330
 
 
 
1331
  def clear_textbox():
1332
  return ""
1333
 
@@ -1337,6 +771,8 @@ def show_map_if_details(history,choice):
1337
  else:
1338
  return gr.update(visible(False), "")
1339
 
 
 
1340
  def generate_audio_elevenlabs(text):
1341
  XI_API_KEY = os.environ['ELEVENLABS_API']
1342
  VOICE_ID = 'd9MIrwLnvDeH7aZb61E9' # Replace with your voice ID
@@ -1381,83 +817,20 @@ def generate_image(prompt):
1381
  return image
1382
 
1383
  # Hardcoded prompt for image generation
1384
- hardcoded_prompt_1 = "Give a high quality photograph of a great looking red 2026 toyota coupe against a skyline setting in the night, michael mann style in omaha enticing the consumer to buy this product"
1385
- hardcoded_prompt_2 = "A vibrant and dynamic football game scene in the style of Peter Paul Rubens, showcasing the intense match between Alabama and Nebraska. The players are depicted with the dramatic, muscular physiques and expressive faces typical of Rubens' style. The Alabama team is wearing their iconic crimson and white uniforms, while the Nebraska team is in their classic red and white attire. The scene is filled with action, with players in mid-motion, tackling, running, and catching the ball. The background features a grand stadium filled with cheering fans, banners, and the natural landscape in the distance. The colors are rich and vibrant, with a strong use of light and shadow to create depth and drama. The overall atmosphere captures the intensity and excitement of the game, infused with the grandeur and dynamism characteristic of Rubens' work."
 
 
1386
  hardcoded_prompt_3 = "Create a high-energy scene of a DJ performing on a large stage with vibrant lights, colorful lasers, a lively dancing crowd, and various electronic equipment in the background."
1387
 
 
1388
  def update_images():
1389
  image_1 = generate_image(hardcoded_prompt_1)
1390
  image_2 = generate_image(hardcoded_prompt_2)
1391
  image_3 = generate_image(hardcoded_prompt_3)
1392
  return image_1, image_2, image_3
1393
 
1394
- # Database setup
1395
- def create_database():
1396
- conn = sqlite3.connect('user_credentials.db')
1397
- cursor = conn.cursor()
1398
- cursor.execute('''
1399
- CREATE TABLE IF NOT EXISTS users (
1400
- id INTEGER PRIMARY KEY,
1401
- username TEXT UNIQUE,
1402
- password TEXT
1403
- )
1404
- ''')
1405
- conn.commit()
1406
- conn.close()
1407
-
1408
- def signup_user(username, password):
1409
- conn = sqlite3.connect('user_credentials.db')
1410
- cursor = conn.cursor()
1411
- hashed_password = bcrypt.hash(password)
1412
- try:
1413
- cursor.execute('INSERT INTO users (username, password) VALUES (?, ?)', (username, hashed_password))
1414
- conn.commit()
1415
- return "Signup successful!"
1416
- except sqlite3.IntegrityError:
1417
- return "Username already exists!"
1418
- finally:
1419
- conn.close()
1420
-
1421
- def login_user(username, password):
1422
- conn = sqlite3.connect('user_credentials.db')
1423
- cursor = conn.cursor()
1424
- cursor.execute('SELECT password FROM users WHERE username = ?', (username,))
1425
- result = cursor.fetchone()
1426
- conn.close()
1427
- if result and bcrypt.verify(password, result[0]):
1428
- return "Login successful!"
1429
- else:
1430
- return "Invalid username or password."
1431
-
1432
- # Initialize database
1433
- create_database()
1434
-
1435
- def signup(username, password, password_confirmation):
1436
- if password != password_confirmation:
1437
- return "Passwords do not match."
1438
- return signup_user(username, password)
1439
-
1440
- def login(username, password):
1441
- return login_user(username, password)
1442
-
1443
- def toggle_login_signup(show_login):
1444
- if show_login:
1445
- return gr.update(visible=True), gr.update(visible=False)
1446
- else:
1447
- return gr.update(visible=False), gr.update(visible(True))
1448
-
1449
- def toggle_login_logout(is_logged_in):
1450
- if is_logged_in:
1451
- return "Logout"
1452
- else:
1453
- return "Login"
1454
-
1455
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1456
- is_logged_in = gr.State(False)
1457
-
1458
- def toggle_login_status(is_logged_in):
1459
- is_logged_in = not is_logged_in
1460
- return gr.update(value=toggle_login_logout(is_logged_in)), is_logged_in
1461
 
1462
  with gr.Row():
1463
  with gr.Column():
@@ -1494,43 +867,13 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1494
  image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
1495
  image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
1496
 
 
1497
  refresh_button = gr.Button("Refresh Images")
1498
  refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
1499
-
1500
- with gr.Row():
1501
- with gr.Column():
1502
- login_button = gr.Button("Login")
1503
- signup_button = gr.Button("Signup")
1504
-
1505
- login_form = gr.Column(visible=False)
1506
- with login_form:
1507
- gr.Markdown("<h2>Login</h2>")
1508
- login_username = gr.Textbox(placeholder="Username")
1509
- login_password = gr.Textbox(placeholder="Password", type="password")
1510
- login_form_button = gr.Button("Login")
1511
- login_message = gr.Textbox(interactive=False)
1512
- login_form_button.click(fn=login, inputs=[login_username, login_password], outputs=[login_message, login_form, signup_button]).then(
1513
- fn=lambda: (gr.update(visible=False), gr.update(visible=False), gr.update(value="Logout")), inputs=None, outputs=[login_form, signup_form, login_button]
1514
- )
1515
- gr.Button("Close").click(fn=lambda: gr.update(visible(False)), inputs=None, outputs=login_form)
1516
- login_button.click(fn=toggle_login_signup, inputs=[gr.State(True)], outputs=[login_form, signup_form])
1517
-
1518
- signup_form = gr.Column(visible=False)
1519
- with signup_form:
1520
- gr.Markdown("<h2>Signup</h2>")
1521
- signup_username = gr.Textbox(placeholder="Username")
1522
- signup_password = gr.Textbox(placeholder="Password", type="password")
1523
- signup_password_confirmation = gr.Textbox(placeholder="Confirm Password", type="password")
1524
- signup_form_button = gr.Button("Signup")
1525
- signup_message = gr.Textbox(interactive=False)
1526
- signup_form_button.click(fn=signup, inputs=[signup_username, signup_password, signup_password_confirmation], outputs=[signup_message, signup_form, signup_button]).then(
1527
- fn=lambda: gr.update(visible(False)), inputs=None, outputs=signup_form
1528
- )
1529
- gr.Button("Close").click(fn=lambda: gr.update(visible=False), inputs=None, outputs=signup_form)
1530
- signup_button.click(fn=toggle_login_signup, inputs=[gr.State(False)], outputs=[signup_form, login_form])
1531
-
1532
- login_form_button.click(fn=toggle_login_status, inputs=[is_logged_in], outputs=[login_button, is_logged_in])
1533
- login_button.click(fn=toggle_login_status, inputs=[is_logged_in], outputs=[login_button, is_logged_in])
1534
 
1535
  demo.queue()
1536
  demo.launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import re
3
  import time
 
23
  from langchain.agents import Tool, initialize_agent
24
  from huggingface_hub import login
25
 
 
 
 
26
  # Check if the token is already set in the environment variables
27
  hf_token = os.getenv("HF_TOKEN")
28
 
 
36
  # Your application logic goes here
37
  print("Logged in successfully to Hugging Face Hub!")
38
 
39
+
40
+
41
  # Set up logging
42
  logging.basicConfig(level=logging.DEBUG)
43
 
 
62
  return_messages=True
63
  )
64
 
65
+ def get_current_time_and_date():
66
+ now = datetime.now()
67
+ return now.strftime("%Y-%m-%d %H:%M:%S")
68
+
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}'
153
 
154
+ # response = requests.get(url)
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;
162
+ # color: #333;
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
+ # }
170
+ # .event-item:hover {
171
+ # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
172
+ # background-color: #e6f7ff;
173
+ # }
174
+ # .event-item a {
175
+ # color: #1E90FF;
176
+ # text-decoration: none;
177
+ # font-weight: bold;
178
+ # }
179
+ # .event-item a:hover {
180
+ # text-decoration: underline;
181
+ # }
182
+ # .event-preview {
183
+ # position: absolute;
184
+ # display: none;
185
+ # border: 1px solid #ccc;
186
+ # border-radius: 5px;
187
+ # box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
188
+ # background-color: white;
189
+ # z-index: 1000;
190
+ # max-width: 300px;
191
+ # padding: 10px;
192
+ # font-family: 'Verdana', sans-serif;
193
+ # color: #333;
194
+ # }
195
+ # </style>
196
+ # <script>
197
+ # function showPreview(event, previewContent) {
198
+ # var previewBox = document.getElementById('event-preview');
199
+ # previewBox.innerHTML = previewContent;
200
+ # previewBox.style.left = event.pageX + 'px';
201
+ # previewBox.style.top = event.pageY + 'px';
202
+ # previewBox.style.display = 'block';
203
+ # }
204
+ # function hidePreview() {
205
+ # var previewBox = document.getElementById('event-preview');
206
+ # previewBox.style.display = 'none';
207
+ # }
208
+ # </script>
209
+ # <div id="event-preview" class="event-preview"></div>
210
+ # """
211
+ # for index, event in enumerate(events_results):
212
+ # title = event.get("title", "No title")
213
+ # date = event.get("date", "No date")
214
+ # location = event.get("address", "No location")
215
+ # link = event.get("link", "#")
216
+ # events_html += f"""
217
+ # <div class="event-item" onmouseover="showPreview(event, 'Date: {date}<br>Location: {location}')" onmouseout="hidePreview()">
218
+ # <a href='{link}' target='_blank'>{index + 1}. {title}</a>
219
+ # <p>Date: {date}<br>Location: {location}</p>
220
+ # </div>
221
+ # """
222
+ # return events_html
223
+ # else:
224
+ # return "<p>Failed to fetch local events</p>"
225
 
226
  def fetch_local_events():
227
  api_key = os.environ['SERP_API']
228
  url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Omaha&hl=en&gl=us&api_key={api_key}'
229
 
230
  response = requests.get(url)
231
+ if response.status_code == 200:
232
  events_results = response.json().get("events_results", [])
233
  events_html = """
234
  <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Events</h2>
 
264
  else:
265
  return "<p>Failed to fetch local events</p>"
266
 
267
+
268
+ # def fetch_local_weather():
269
+ # try:
270
+ # api_key = os.environ['WEATHER_API']
271
+ # url = f'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/omaha?unitGroup=metric&include=events%2Calerts%2Chours%2Cdays%2Ccurrent&key={api_key}'
272
+ # response = requests.get(url)
273
+ # response.raise_for_status()
274
+ # jsonData = response.json()
275
+
276
+ # current_conditions = jsonData.get("currentConditions", {})
277
+ # temp_celsius = current_conditions.get("temp", "N/A")
278
+
279
+ # if temp_celsius != "N/A":
280
+ # temp_fahrenheit = int((temp_celsius * 9/5) + 32)
281
+ # else:
282
+ # temp_fahrenheit = "N/A"
283
+
284
+ # condition = current_conditions.get("conditions", "N/A")
285
+ # humidity = current_conditions.get("humidity", "N/A")
286
+
287
+ # weather_html = f"""
288
+ # <div class="weather-theme">
289
+ # <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Weather</h2>
290
+ # <div class="weather-content">
291
+ # <div class="weather-icon">
292
+ # <img src="https://www.weatherbit.io/static/img/icons/{get_weather_icon(condition)}.png" alt="{condition}" style="width: 100px; height: 100px;">
293
+ # </div>
294
+ # <div class="weather-details">
295
+ # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Temperature: {temp_fahrenheit}°F</p>
296
+ # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Condition: {condition}</p>
297
+ # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Humidity: {humidity}%</p>
298
+ # </div>
299
+ # </div>
300
+ # </div>
301
+ # <style>
302
+ # .weather-theme {{
303
+ # animation: backgroundAnimation 10s infinite alternate;
304
+ # border: 2px solid red; /* Added red border */
305
+ # border-radius: 10px;
306
+ # padding: 10px;
307
+ # margin-bottom: 15px;
308
+ # background: linear-gradient(45deg, #ffcc33, #ff6666, #ffcc33, #ff6666);
309
+ # background-size: 400% 400%;
310
+ # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
311
+ # transition: box-shadow 0.3s ease, background-color 0.3s ease;
312
+ # }}
313
+ # .weather-theme:hover {{
314
+ # box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
315
+ # background-position: 100% 100%;
316
+ # }}
317
+ # @keyframes backgroundAnimation {{
318
+ # 0% {{ background-position: 0% 50%; }}
319
+ # 100% {{ background-position: 100% 50%; }}
320
+ # }}
321
+ # .weather-content {{
322
+ # display: flex;
323
+ # align-items: center;
324
+ # }}
325
+ # .weather-icon {{
326
+ # flex: 1;
327
+ # }}
328
+ # .weather-details {{
329
+ # flex: 3;
330
+ # }}
331
+ # </style>
332
+ # """
333
+ # return weather_html
334
+ # except requests.exceptions.RequestException as e:
335
+ # return f"<p>Failed to fetch local weather: {e}</p>"
336
  def fetch_local_weather():
337
  try:
338
  api_key = os.environ['WEATHER_API']
 
418
  }
419
  return condition_map.get(condition, "c04d")
420
 
421
+ # Update prompt templates to include fetched details
422
+
423
  current_time_and_date = get_current_time_and_date()
424
 
425
+
426
+
427
  # Define prompt templates
428
  template1 = """You are an expert concierge who is helpful and a renowned guide for Omaha, Nebraska. Based on weather being a sunny bright day and the today's date is 20th june 2024, use the following pieces of context,
429
  memory, and message history, along with your knowledge of perennial events in Omaha, Nebraska, to answer the question at the end. If you don't know the answer, just say "Homie, I need to get more data for this," and don't try to make up an answer.
 
440
  Question: {question}
441
  Helpful Answer:"""
442
 
443
+
444
+
445
  QA_CHAIN_PROMPT_1 = PromptTemplate(input_variables=["context", "question"], template=template1)
446
  QA_CHAIN_PROMPT_2 = PromptTemplate(input_variables=["context", "question"], template=template2)
447
 
448
+
449
  # Define the retrieval QA chain
450
  def build_qa_chain(prompt_template):
451
  qa_chain = RetrievalQA.from_chain_type(
 
493
  # Extract addresses for mapping regardless of the choice
494
  addresses = extract_addresses(response['output'])
495
  return response['output'], addresses
496
+
497
+
498
 
499
  def bot(history, choice):
500
  if not history:
 
514
  audio_path = audio_future.result()
515
  yield history, audio_path
516
 
517
+
518
  def add_message(history, message):
519
  history.append((message, None))
520
  return history, gr.Textbox(value="", interactive=True, placeholder="Enter message or upload file...", show_label=False)
 
562
  map_html = m._repr_html_()
563
  return map_html
564
 
565
+ # def fetch_local_news():
566
+ # api_key = os.environ['SERP_API']
567
+ # url = f'https://serpapi.com/search.json?engine=google_news&q=omaha headline&api_key={api_key}'
568
+ # response = requests.get(url)
569
+ # if response.status_code == 200:
570
+ # results = response.json().get("news_results", [])
571
+ # news_html = """
572
+ # <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Omaha Today </h2>
573
+ # <style>
574
+ # .news-item {
575
+ # font-family: 'Verdana', sans-serif;
576
+ # color: #333;
577
+ # background-color: #f0f8ff;
578
+ # margin-bottom: 15px;
579
+ # padding: 10px;
580
+ # border: 2px solid red; /* Added red border */
581
+ # border-radius: 5px;
582
+ # transition: box-shadow 0.3s ease, background-color 0.3s ease;
583
+ # font-weight: bold;
584
+ # }
585
+ # .news-item:hover {
586
+ # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
587
+ # background-color: #e6f7ff;
588
+ # }
589
+ # .news-item a {
590
+ # color: #1E90FF;
591
+ # text-decoration: none;
592
+ # font-weight: bold;
593
+ # }
594
+ # .news-item a:hover {
595
+ # text-decoration: underline;
596
+ # }
597
+ # .news-preview {
598
+ # position: absolute;
599
+ # display: none;
600
+ # border: 1px solid #ccc;
601
+ # border-radius: 5px;
602
+ # box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
603
+ # background-color: white;
604
+ # z-index: 1000;
605
+ # max-width: 300px;
606
+ # padding: 10px;
607
+ # font-family: 'Verdana', sans-serif;
608
+ # color: #333;
609
+ # }
610
+ # </style>
611
+ # <script>
612
+ # function showPreview(event, previewContent) {
613
+ # var previewBox = document.getElementById('news-preview');
614
+ # previewBox.innerHTML = previewContent;
615
+ # previewBox.style.left = event.pageX + 'px';
616
+ # previewBox.style.top = event.pageY + 'px';
617
+ # previewBox.style.display = 'block';
618
+ # }
619
+ # function hidePreview() {
620
+ # var previewBox = document.getElementById('news-preview');
621
+ # previewBox.style.display = 'none';
622
+ # }
623
+ # </script>
624
+ # <div id="news-preview" class="news-preview"></div>
625
+ # """
626
+ # for index, result in enumerate(results[:7]):
627
+ # title = result.get("title", "No title")
628
+ # link = result.get("link", "#")
629
+ # snippet = result.get("snippet", "")
630
+ # news_html += f"""
631
+ # <div class="news-item" onmouseover="showPreview(event, '{snippet}')" onmouseout="hidePreview()">
632
+ # <a href='{link}' target='_blank'>{index + 1}. {title}</a>
633
+ # <p>{snippet}</p>
634
+ # </div>
635
+ # """
636
+ # return news_html
637
+ # else:
638
+ # return "<p>Failed to fetch local news</p>"
639
+
640
  def fetch_local_news():
641
  api_key = os.environ['SERP_API']
642
  url = f'https://serpapi.com/search.json?engine=google_news&q=omaha headline&api_key={api_key}'
643
  response = requests.get(url)
644
+ if response.status_code == 200:
645
  results = response.json().get("news_results", [])
646
  news_html = """
647
  <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Omaha Today</h2>
 
711
  else:
712
  return "<p>Failed to fetch local news</p>"
713
 
714
+
715
  # Voice Control
716
  import numpy as np
717
  import torch
 
730
 
731
  base_audio_drive = "/data/audio"
732
 
733
+ import numpy as np
734
+
735
  def transcribe_function(stream, new_chunk):
736
  try:
737
  sr, y = new_chunk[0], new_chunk[1]
 
751
  full_text = result.get("text", "")
752
 
753
  return stream, full_text, result
754
+
755
 
756
  def update_map_with_response(history):
757
  if not history:
 
760
  addresses = extract_addresses(response)
761
  return generate_map(addresses)
762
 
763
+
764
+
765
  def clear_textbox():
766
  return ""
767
 
 
771
  else:
772
  return gr.update(visible(False), "")
773
 
774
+
775
+
776
  def generate_audio_elevenlabs(text):
777
  XI_API_KEY = os.environ['ELEVENLABS_API']
778
  VOICE_ID = 'd9MIrwLnvDeH7aZb61E9' # Replace with your voice ID
 
817
  return image
818
 
819
  # Hardcoded prompt for image generation
820
+ # hardcoded_prompt_1 = "Useing The top events like 'Summer Art Festival'and Date - 06/19/2024 ,Weather-Sunny Bright Day.Create Highly Visually Compelling High Resolution and High Quality Photographics Advatizement for 'Toyota'"
821
+ hardcoded_prompt_1="Give a high quality photograph of a great looking red 2026 toyota coupe against a skyline setting in th night, michael mann style in omaha enticing the consumer to buy this product"
822
+ # hardcoded_prompt_2 = "Create a vibrant poster of Nebraska with beautiful weather, featuring picturesque landscapes, clear skies, and the word 'Nebraska' prominently displayed."
823
+ hardcoded_prompt_2="A vibrant and dynamic football game scene in the style of Peter Paul Rubens, showcasing the intense match between Alabama and Nebraska. The players are depicted with the dramatic, muscular physiques and expressive faces typical of Rubens' style. The Alabama team is wearing their iconic crimson and white uniforms, while the Nebraska team is in their classic red and white attire. The scene is filled with action, with players in mid-motion, tackling, running, and catching the ball. The background features a grand stadium filled with cheering fans, banners, and the natural landscape in the distance. The colors are rich and vibrant, with a strong use of light and shadow to create depth and drama. The overall atmosphere captures the intensity and excitement of the game, infused with the grandeur and dynamism characteristic of Rubens' work."
824
  hardcoded_prompt_3 = "Create a high-energy scene of a DJ performing on a large stage with vibrant lights, colorful lasers, a lively dancing crowd, and various electronic equipment in the background."
825
 
826
+
827
  def update_images():
828
  image_1 = generate_image(hardcoded_prompt_1)
829
  image_2 = generate_image(hardcoded_prompt_2)
830
  image_3 = generate_image(hardcoded_prompt_3)
831
  return image_1, image_2, image_3
832
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
833
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
 
 
 
 
 
834
 
835
  with gr.Row():
836
  with gr.Column():
 
867
  image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
868
  image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
869
 
870
+
871
  refresh_button = gr.Button("Refresh Images")
872
  refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
873
 
874
  demo.queue()
875
  demo.launch(share=True)
876
+
877
+
878
+
879
+