Pijush2023 commited on
Commit
3f3dd14
·
verified ·
1 Parent(s): a4dc3fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -499
app.py CHANGED
@@ -69,160 +69,6 @@ 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}'
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}'
@@ -264,75 +110,6 @@ def fetch_local_events():
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']
@@ -422,8 +199,6 @@ def get_weather_icon(condition):
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,12 +215,9 @@ Keep the answer short and sweet and crisp. Always say "It was my pleasure!" at t
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,8 +265,6 @@ def generate_answer(message, choice):
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,7 +284,6 @@ def bot(history, choice):
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)
@@ -555,88 +324,13 @@ def generate_map(location_names):
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}'
@@ -711,7 +405,6 @@ def fetch_local_news():
711
  else:
712
  return "<p>Failed to fetch local news</p>"
713
 
714
-
715
  # Voice Control
716
  import numpy as np
717
  import torch
@@ -760,8 +453,6 @@ def update_map_with_response(history):
760
  addresses = extract_addresses(response)
761
  return generate_map(addresses)
762
 
763
-
764
-
765
  def clear_textbox():
766
  return ""
767
 
@@ -771,8 +462,6 @@ def show_map_if_details(history,choice):
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,108 +506,21 @@ def generate_image(prompt):
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
-
834
-
835
- # import sqlite3
836
- # import bcrypt
837
- # import gradio as gr
838
-
839
- # # Set up the database
840
- # def initialize_database():
841
- # conn = sqlite3.connect('user_data.db')
842
- # c = conn.cursor()
843
- # c.execute('''
844
- # CREATE TABLE IF NOT EXISTS users (
845
- # id INTEGER PRIMARY KEY AUTOINCREMENT,
846
- # email TEXT UNIQUE NOT NULL,
847
- # password TEXT NOT NULL
848
- # )
849
- # ''')
850
- # conn.commit()
851
- # conn.close()
852
-
853
- # # Email validation
854
- # def is_valid_email(email):
855
- # regex = r'^\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
856
- # if re.match(regex, email):
857
- # return True
858
- # else:
859
- # return False
860
-
861
- # # Hashing and checking passwords
862
- # def hash_password(password):
863
- # return bcrypt.hashpw(password.encode(), bcrypt.gensalt())
864
-
865
- # def check_password(password, hashed):
866
- # return bcrypt.checkpw(password.encode(), hashed)
867
-
868
- # # User signup and login functions
869
- # def signup_user(email, password):
870
- # if not is_valid_email(email):
871
- # return "Invalid email!"
872
- # conn = sqlite3.connect('user_data.db')
873
- # c = conn.cursor()
874
- # try:
875
- # c.execute("INSERT INTO users (email, password) VALUES (?, ?)", (email, hash_password(password)))
876
- # conn.commit()
877
- # return "User signed up successfully!"
878
- # except sqlite3.IntegrityError:
879
- # return "Email already registered!"
880
- # finally:
881
- # conn.close()
882
-
883
- # def login_user(email, password, state):
884
- # if not is_valid_email(email):
885
- # return "Invalid email!", state
886
- # conn = sqlite3.connect('user_data.db')
887
- # c = conn.cursor()
888
- # c.execute("SELECT password FROM users WHERE email = ?", (email,))
889
- # result = c.fetchone()
890
- # conn.close()
891
- # if result and check_password(password, result[0]):
892
- # state['authenticated'] = True
893
- # return "Login successful!", state
894
- # else:
895
- # return "Invalid email or password!", state
896
-
897
- # def logout_user(state):
898
- # state['authenticated'] = False
899
- # return "Logged out successfully!", state
900
-
901
- # # Define the necessary functions
902
- # def signup(email, password):
903
- # return signup_user(email, password)
904
-
905
- # def login(email, password, state):
906
- # message, state = login_user(email, password, state)
907
- # return message, state, "Logout" if state['authenticated'] else "Login"
908
-
909
- # def logout(state):
910
- # message, state = logout_user(state)
911
- # return message, state, "Login", "", ""
912
-
913
- # # Initialize database
914
- # initialize_database()
915
-
916
  # Google OAuth2 settings
917
  client_id = os.getenv("GOOGLE_CLIENT_ID")
918
  client_secret = os.getenv("GOOGLE_CLIENT_SECRET")
919
  authorization_base_url = 'https://accounts.google.com/o/oauth2/auth'
920
  token_url = 'https://accounts.google.com/o/oauth2/token'
921
- #redirect_uri = 'http://localhost:7860/callback'
922
  redirect_uri = 'https://huggingface.co/spaces/Pijush2023/omaha062028v3'
923
 
924
  scope = [
@@ -952,7 +554,6 @@ def create_gradio_interface():
952
  def greet(name):
953
  return f"Hello {name}, welcome to the Gradio app!"
954
 
955
-
956
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
957
  if user_info.get('authenticated', False):
958
  gr.Markdown(f"### Hello, {user_info['name']}! Welcome to the Gradio App")
@@ -1004,102 +605,4 @@ def main(params=None):
1004
  if __name__ == "__main__":
1005
  import sys
1006
  params = sys.argv[1] if len(sys.argv) > 1 else None
1007
- main(params)
1008
-
1009
-
1010
-
1011
-
1012
-
1013
-
1014
-
1015
-
1016
-
1017
-
1018
-
1019
-
1020
-
1021
-
1022
-
1023
-
1024
-
1025
-
1026
-
1027
-
1028
-
1029
-
1030
-
1031
-
1032
-
1033
-
1034
-
1035
-
1036
-
1037
-
1038
-
1039
-
1040
-
1041
-
1042
-
1043
-
1044
-
1045
-
1046
-
1047
-
1048
-
1049
-
1050
-
1051
-
1052
-
1053
- # with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1054
- # state = gr.State({'authenticated': True})
1055
- # if user_info:
1056
- # gr.Markdown(f"### Hello, {user_info['name']}! Welcome to the Gradio App")
1057
- # name = gr.Textbox(label="Enter your name")
1058
- # greet_btn = gr.Button("Greet")
1059
- # output = gr.Textbox(label="Greeting")
1060
- # greet_btn.click(greet, inputs=name, outputs=output)
1061
-
1062
- # chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
1063
- # choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
1064
-
1065
- # gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
1066
- # chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
1067
- # chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
1068
- # bot_msg = chat_msg.then(bot, [chatbot, choice], [chatbot, gr.Audio(interactive=False, autoplay=True)])
1069
- # bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
1070
- # chatbot.like(print_like_dislike, None, None)
1071
- # clear_button = gr.Button("Clear")
1072
- # clear_button.click(fn=clear_textbox, inputs=None, outputs=chat_input)
1073
-
1074
- # audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy')
1075
- # audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="SAMLOne_real_time")
1076
-
1077
- # gr.Markdown("<h1 style='color: red;'>Map</h1>", elem_id="location-markdown")
1078
- # location_output = gr.HTML()
1079
- # bot_msg.then(show_map_if_details, [chatbot, choice], [location_output, location_output])
1080
-
1081
- # weather_output = gr.HTML(value=fetch_local_weather())
1082
- # news_output = gr.HTML(value=fetch_local_news())
1083
- # events_output = gr.HTML(value=fetch_local_events())
1084
-
1085
- # image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
1086
- # image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
1087
- # image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
1088
- # refresh_button = gr.Button("Refresh Images")
1089
- # refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
1090
- # else:
1091
- # login_url = login()
1092
- # gr.Markdown(f"[Login with Google]({login_url})")
1093
-
1094
- # return demo
1095
-
1096
- # def main(params=None):
1097
- # if params:
1098
- # callback(params)
1099
- # demo = create_gradio_interface()
1100
- # demo.launch()
1101
-
1102
- # if __name__ == "__main__":
1103
- # import sys
1104
- # params = sys.argv[1] if len(sys.argv) > 1 else None
1105
- # main(params)
 
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}'
 
110
  else:
111
  return "<p>Failed to fetch local events</p>"
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  def fetch_local_weather():
114
  try:
115
  api_key = os.environ['WEATHER_API']
 
199
 
200
  current_time_and_date = get_current_time_and_date()
201
 
 
 
202
  # Define prompt templates
203
  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,
204
  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.
 
215
  Question: {question}
216
  Helpful Answer:"""
217
 
 
 
218
  QA_CHAIN_PROMPT_1 = PromptTemplate(input_variables=["context", "question"], template=template1)
219
  QA_CHAIN_PROMPT_2 = PromptTemplate(input_variables=["context", "question"], template=template2)
220
 
 
221
  # Define the retrieval QA chain
222
  def build_qa_chain(prompt_template):
223
  qa_chain = RetrievalQA.from_chain_type(
 
265
  # Extract addresses for mapping regardless of the choice
266
  addresses = extract_addresses(response['output'])
267
  return response['output'], addresses
 
 
268
 
269
  def bot(history, choice):
270
  if not history:
 
284
  audio_path = audio_future.result()
285
  yield history, audio_path
286
 
 
287
  def add_message(history, message):
288
  history.append((message, None))
289
  return history, gr.Textbox(value="", interactive=True, placeholder="Enter message or upload file...", show_label=False)
 
324
  if geocode_result:
325
  location = geocode_result[0]['geometry']['location']
326
  folium.Marker(
327
+ [location['lat'], 'lng'],
328
  tooltip=f"{geocode_result[0]['formatted_address']}"
329
  ).add_to(m)
330
 
331
  map_html = m._repr_html_()
332
  return map_html
333
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
334
  def fetch_local_news():
335
  api_key = os.environ['SERP_API']
336
  url = f'https://serpapi.com/search.json?engine=google_news&q=omaha headline&api_key={api_key}'
 
405
  else:
406
  return "<p>Failed to fetch local news</p>"
407
 
 
408
  # Voice Control
409
  import numpy as np
410
  import torch
 
453
  addresses = extract_addresses(response)
454
  return generate_map(addresses)
455
 
 
 
456
  def clear_textbox():
457
  return ""
458
 
 
462
  else:
463
  return gr.update(visible(False), "")
464
 
 
 
465
  def generate_audio_elevenlabs(text):
466
  XI_API_KEY = os.environ['ELEVENLABS_API']
467
  VOICE_ID = 'd9MIrwLnvDeH7aZb61E9' # Replace with your voice ID
 
506
  return image
507
 
508
  # Hardcoded prompt for image generation
 
509
  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"
 
510
  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."
511
  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."
512
 
 
513
  def update_images():
514
  image_1 = generate_image(hardcoded_prompt_1)
515
  image_2 = generate_image(hardcoded_prompt_2)
516
  image_3 = generate_image(hardcoded_prompt_3)
517
  return image_1, image_2, image_3
518
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
519
  # Google OAuth2 settings
520
  client_id = os.getenv("GOOGLE_CLIENT_ID")
521
  client_secret = os.getenv("GOOGLE_CLIENT_SECRET")
522
  authorization_base_url = 'https://accounts.google.com/o/oauth2/auth'
523
  token_url = 'https://accounts.google.com/o/oauth2/token'
 
524
  redirect_uri = 'https://huggingface.co/spaces/Pijush2023/omaha062028v3'
525
 
526
  scope = [
 
554
  def greet(name):
555
  return f"Hello {name}, welcome to the Gradio app!"
556
 
 
557
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
558
  if user_info.get('authenticated', False):
559
  gr.Markdown(f"### Hello, {user_info['name']}! Welcome to the Gradio App")
 
605
  if __name__ == "__main__":
606
  import sys
607
  params = sys.argv[1] if len(sys.argv) > 1 else None
608
+ main(params)