Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -473,12 +473,10 @@ def generate_answer(message, choice, retrieval_mode, selected_model):
|
|
| 473 |
logging.error(traceback.format_exc())
|
| 474 |
return "Sorry, I encountered an error while processing your request.", []
|
| 475 |
|
| 476 |
-
def handle_retrieval_mode_change(
|
| 477 |
-
if
|
| 478 |
-
# Disable retrieval mode and select style when Phi-3.5 is selected
|
| 479 |
return gr.update(interactive=False), gr.update(interactive=False)
|
| 480 |
else:
|
| 481 |
-
# Enable retrieval mode and select style for other models
|
| 482 |
return gr.update(interactive=True), gr.update(interactive=True)
|
| 483 |
|
| 484 |
|
|
@@ -686,7 +684,7 @@ def show_map_if_details(history, choice):
|
|
| 686 |
|
| 687 |
def generate_audio_elevenlabs(text):
|
| 688 |
XI_API_KEY = os.environ['ELEVENLABS_API']
|
| 689 |
-
VOICE_ID = '
|
| 690 |
tts_url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}/stream"
|
| 691 |
headers = {
|
| 692 |
"Accept": "application/json",
|
|
@@ -953,7 +951,16 @@ def handle_retrieval_mode_change(choice):
|
|
| 953 |
else:
|
| 954 |
return gr.update(interactive=True), gr.update(interactive=True)
|
| 955 |
|
| 956 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 957 |
|
| 958 |
|
| 959 |
|
|
@@ -961,7 +968,6 @@ def handle_retrieval_mode_change(choice):
|
|
| 961 |
def format_restaurant_hotel_info(name, link, location, phone, rating, reviews, snippet):
|
| 962 |
return f"""
|
| 963 |
{name}
|
| 964 |
-
|
| 965 |
- Link: {link}
|
| 966 |
- Location: {location}
|
| 967 |
- Contact No: {phone}
|
|
@@ -1008,7 +1014,6 @@ def fetch_yelp_restaurants():
|
|
| 1008 |
def format_hotel_info(name, link, location, rate_per_night, total_rate, description, check_in_time, check_out_time, amenities):
|
| 1009 |
return f"""
|
| 1010 |
{name}
|
| 1011 |
-
|
| 1012 |
- Link: {link}
|
| 1013 |
- Location: {location}
|
| 1014 |
- Rate per Night: {rate_per_night} (Before taxes/fees: {total_rate})
|
|
@@ -1073,7 +1078,6 @@ def fetch_google_hotels(query="Birmingham Hotel", check_in=current_date1, check_
|
|
| 1073 |
def format_flight_info(flight_number, departure_airport, departure_time, arrival_airport, arrival_time, duration, airplane):
|
| 1074 |
return f"""
|
| 1075 |
Flight {flight_number}
|
| 1076 |
-
|
| 1077 |
- Departure: {departure_airport} at {departure_time}
|
| 1078 |
- Arrival: {arrival_airport} at {arrival_time}
|
| 1079 |
- Duration: {duration} minutes
|
|
@@ -1126,6 +1130,74 @@ def fetch_google_flights(departure_id="JFK", arrival_id="BHM", outbound_date=cur
|
|
| 1126 |
|
| 1127 |
return flight_info
|
| 1128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1129 |
with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
| 1130 |
with gr.Row():
|
| 1131 |
with gr.Column():
|
|
@@ -1135,11 +1207,9 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
|
| 1135 |
choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
|
| 1136 |
retrieval_mode = gr.Radio(label="Retrieval Mode", choices=["VDB", "KGF"], value="VDB")
|
| 1137 |
model_choice = gr.Dropdown(label="Choose Model", choices=["GPT-4o", "Phi-3.5"], value="GPT-4o")
|
| 1138 |
-
|
| 1139 |
-
|
| 1140 |
-
# Link the dropdown change to handle_retrieval_mode_change
|
| 1141 |
-
model_choice.change(fn=handle_retrieval_mode_change, inputs=model_choice, outputs=[retrieval_mode, choice])
|
| 1142 |
|
|
|
|
|
|
|
| 1143 |
|
| 1144 |
gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
|
| 1145 |
|
|
@@ -1148,7 +1218,7 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
|
| 1148 |
retriever_button = gr.Button("Retriever")
|
| 1149 |
|
| 1150 |
clear_button = gr.Button("Clear")
|
| 1151 |
-
clear_button.click(lambda:[None,None], outputs=[chat_input, state])
|
| 1152 |
|
| 1153 |
gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
|
| 1154 |
location_output = gr.HTML()
|
|
@@ -1178,16 +1248,10 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
|
| 1178 |
audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy', every=0.1)
|
| 1179 |
audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="voice_query_to_text")
|
| 1180 |
|
| 1181 |
-
# retrieval_mode.change(fn=handle_retrieval_mode_change, inputs=retrieval_mode, outputs=[choice, choice])
|
| 1182 |
-
model_choice.change(fn=handle_retrieval_mode_change, inputs=model_choice, outputs=[choice, retrieval_mode])
|
| 1183 |
-
|
| 1184 |
-
|
| 1185 |
# with gr.Column():
|
| 1186 |
# weather_output = gr.HTML(value=fetch_local_weather())
|
| 1187 |
# news_output = gr.HTML(value=fetch_local_news())
|
| 1188 |
# events_output = gr.HTML(value=fetch_local_events())
|
| 1189 |
|
| 1190 |
-
|
| 1191 |
-
|
| 1192 |
demo.queue()
|
| 1193 |
-
demo.launch(share=True)
|
|
|
|
| 473 |
logging.error(traceback.format_exc())
|
| 474 |
return "Sorry, I encountered an error while processing your request.", []
|
| 475 |
|
| 476 |
+
def handle_retrieval_mode_change(choice):
|
| 477 |
+
if choice == "KGF":
|
|
|
|
| 478 |
return gr.update(interactive=False), gr.update(interactive=False)
|
| 479 |
else:
|
|
|
|
| 480 |
return gr.update(interactive=True), gr.update(interactive=True)
|
| 481 |
|
| 482 |
|
|
|
|
| 684 |
|
| 685 |
def generate_audio_elevenlabs(text):
|
| 686 |
XI_API_KEY = os.environ['ELEVENLABS_API']
|
| 687 |
+
VOICE_ID = 'd9MIrwLnvDeH7aZb61E9'
|
| 688 |
tts_url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}/stream"
|
| 689 |
headers = {
|
| 690 |
"Accept": "application/json",
|
|
|
|
| 951 |
else:
|
| 952 |
return gr.update(interactive=True), gr.update(interactive=True)
|
| 953 |
|
| 954 |
+
def handle_model_choice_change(selected_model):
|
| 955 |
+
if selected_model == "Phi-3.5":
|
| 956 |
+
# Disable retrieval mode and select style when Phi-3.5 is selected
|
| 957 |
+
return gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
|
| 958 |
+
elif selected_model == "GPT-4o":
|
| 959 |
+
# Enable retrieval mode and select style for GPT-4o
|
| 960 |
+
return gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)
|
| 961 |
+
else:
|
| 962 |
+
# Default case: allow interaction
|
| 963 |
+
return gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)
|
| 964 |
|
| 965 |
|
| 966 |
|
|
|
|
| 968 |
def format_restaurant_hotel_info(name, link, location, phone, rating, reviews, snippet):
|
| 969 |
return f"""
|
| 970 |
{name}
|
|
|
|
| 971 |
- Link: {link}
|
| 972 |
- Location: {location}
|
| 973 |
- Contact No: {phone}
|
|
|
|
| 1014 |
def format_hotel_info(name, link, location, rate_per_night, total_rate, description, check_in_time, check_out_time, amenities):
|
| 1015 |
return f"""
|
| 1016 |
{name}
|
|
|
|
| 1017 |
- Link: {link}
|
| 1018 |
- Location: {location}
|
| 1019 |
- Rate per Night: {rate_per_night} (Before taxes/fees: {total_rate})
|
|
|
|
| 1078 |
def format_flight_info(flight_number, departure_airport, departure_time, arrival_airport, arrival_time, duration, airplane):
|
| 1079 |
return f"""
|
| 1080 |
Flight {flight_number}
|
|
|
|
| 1081 |
- Departure: {departure_airport} at {departure_time}
|
| 1082 |
- Arrival: {arrival_airport} at {arrival_time}
|
| 1083 |
- Duration: {duration} minutes
|
|
|
|
| 1130 |
|
| 1131 |
return flight_info
|
| 1132 |
|
| 1133 |
+
# with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
| 1134 |
+
# with gr.Row():
|
| 1135 |
+
# with gr.Column():
|
| 1136 |
+
# state = gr.State()
|
| 1137 |
+
|
| 1138 |
+
# chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
|
| 1139 |
+
# choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
|
| 1140 |
+
# retrieval_mode = gr.Radio(label="Retrieval Mode", choices=["VDB", "KGF"], value="VDB")
|
| 1141 |
+
# model_choice = gr.Dropdown(label="Choose Model", choices=["GPT-4o", "Phi-3.5"], value="GPT-4o")
|
| 1142 |
+
|
| 1143 |
+
|
| 1144 |
+
# # Link the dropdown change to handle_retrieval_mode_change
|
| 1145 |
+
# model_choice.change(fn=handle_retrieval_mode_change, inputs=model_choice, outputs=[retrieval_mode, choice])
|
| 1146 |
+
|
| 1147 |
+
|
| 1148 |
+
# gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
|
| 1149 |
+
|
| 1150 |
+
# chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!", placeholder="Hey Radar...!!")
|
| 1151 |
+
# tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta"], value="Alpha")
|
| 1152 |
+
# retriever_button = gr.Button("Retriever")
|
| 1153 |
+
|
| 1154 |
+
# clear_button = gr.Button("Clear")
|
| 1155 |
+
# clear_button.click(lambda:[None,None], outputs=[chat_input, state])
|
| 1156 |
+
|
| 1157 |
+
# gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
|
| 1158 |
+
# location_output = gr.HTML()
|
| 1159 |
+
# audio_output = gr.Audio(interactive=False, autoplay=True)
|
| 1160 |
+
|
| 1161 |
+
# def stop_audio():
|
| 1162 |
+
# audio_output.stop()
|
| 1163 |
+
# return None
|
| 1164 |
+
|
| 1165 |
+
# retriever_sequence = (
|
| 1166 |
+
# retriever_button.click(fn=stop_audio, inputs=[], outputs=[audio_output], api_name="Ask_Retriever")
|
| 1167 |
+
# .then(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input], api_name="voice_query")
|
| 1168 |
+
# .then(fn=bot, inputs=[chatbot, choice, tts_choice, retrieval_mode, model_choice], outputs=[chatbot, audio_output], api_name="generate_voice_response")
|
| 1169 |
+
# .then(fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder")
|
| 1170 |
+
# .then(fn=clear_textbox, inputs=[], outputs=[chat_input])
|
| 1171 |
+
# )
|
| 1172 |
+
|
| 1173 |
+
# chat_input.submit(fn=stop_audio, inputs=[], outputs=[audio_output])
|
| 1174 |
+
# chat_input.submit(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input], api_name="voice_query").then(
|
| 1175 |
+
# fn=bot, inputs=[chatbot, choice, tts_choice, retrieval_mode, model_choice], outputs=[chatbot, audio_output], api_name="generate_voice_response"
|
| 1176 |
+
# ).then(
|
| 1177 |
+
# fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder"
|
| 1178 |
+
# ).then(
|
| 1179 |
+
# fn=clear_textbox, inputs=[], outputs=[chat_input]
|
| 1180 |
+
# )
|
| 1181 |
+
|
| 1182 |
+
# audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy', every=0.1)
|
| 1183 |
+
# audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="voice_query_to_text")
|
| 1184 |
+
|
| 1185 |
+
# # retrieval_mode.change(fn=handle_retrieval_mode_change, inputs=retrieval_mode, outputs=[choice, choice])
|
| 1186 |
+
# model_choice.change(fn=handle_retrieval_mode_change, inputs=model_choice, outputs=[choice, retrieval_mode])
|
| 1187 |
+
|
| 1188 |
+
|
| 1189 |
+
# # with gr.Column():
|
| 1190 |
+
# # weather_output = gr.HTML(value=fetch_local_weather())
|
| 1191 |
+
# # news_output = gr.HTML(value=fetch_local_news())
|
| 1192 |
+
# # events_output = gr.HTML(value=fetch_local_events())
|
| 1193 |
+
|
| 1194 |
+
|
| 1195 |
+
|
| 1196 |
+
# demo.queue()
|
| 1197 |
+
# demo.launch(share=True)
|
| 1198 |
+
|
| 1199 |
+
|
| 1200 |
+
|
| 1201 |
with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
| 1202 |
with gr.Row():
|
| 1203 |
with gr.Column():
|
|
|
|
| 1207 |
choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
|
| 1208 |
retrieval_mode = gr.Radio(label="Retrieval Mode", choices=["VDB", "KGF"], value="VDB")
|
| 1209 |
model_choice = gr.Dropdown(label="Choose Model", choices=["GPT-4o", "Phi-3.5"], value="GPT-4o")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1210 |
|
| 1211 |
+
# Link the dropdown change to handle_model_choice_change
|
| 1212 |
+
model_choice.change(fn=handle_model_choice_change, inputs=model_choice, outputs=[retrieval_mode, choice, choice])
|
| 1213 |
|
| 1214 |
gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
|
| 1215 |
|
|
|
|
| 1218 |
retriever_button = gr.Button("Retriever")
|
| 1219 |
|
| 1220 |
clear_button = gr.Button("Clear")
|
| 1221 |
+
clear_button.click(lambda: [None, None], outputs=[chat_input, state])
|
| 1222 |
|
| 1223 |
gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
|
| 1224 |
location_output = gr.HTML()
|
|
|
|
| 1248 |
audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy', every=0.1)
|
| 1249 |
audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="voice_query_to_text")
|
| 1250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1251 |
# with gr.Column():
|
| 1252 |
# weather_output = gr.HTML(value=fetch_local_weather())
|
| 1253 |
# news_output = gr.HTML(value=fetch_local_news())
|
| 1254 |
# events_output = gr.HTML(value=fetch_local_events())
|
| 1255 |
|
|
|
|
|
|
|
| 1256 |
demo.queue()
|
| 1257 |
+
demo.launch(share=True)
|