Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -223,7 +223,7 @@ def generate_speech_with_gpu(text: str, voice_name: str = 'af', tts_model=TTS_MO
|
|
223 |
print(f"Error generating speech: {str(e)}")
|
224 |
return None
|
225 |
|
226 |
-
def process_query(query: str, history: List[List[str]], selected_voice: str = 'af')
|
227 |
"""Process user query with streaming effect"""
|
228 |
try:
|
229 |
if history is None:
|
@@ -235,13 +235,14 @@ def process_query(query: str, history: List[List[str]], selected_voice: str = 'a
|
|
235 |
|
236 |
current_history = history + [[query, "*Searching...*"]]
|
237 |
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
|
|
245 |
|
246 |
# Generate answer
|
247 |
prompt = format_prompt(query, web_results)
|
@@ -253,13 +254,13 @@ def process_query(query: str, history: List[List[str]], selected_voice: str = 'a
|
|
253 |
|
254 |
# Generate speech from the answer (only if enabled)
|
255 |
if TTS_ENABLED:
|
256 |
-
yield
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
try:
|
264 |
audio = generate_speech_with_gpu(final_answer, selected_voice)
|
265 |
if audio is None:
|
@@ -271,25 +272,26 @@ def process_query(query: str, history: List[List[str]], selected_voice: str = 'a
|
|
271 |
final_answer += "\n\n*TTS is disabled. Audio not available.*"
|
272 |
audio = None
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
|
|
281 |
|
282 |
except Exception as e:
|
283 |
error_message = str(e)
|
284 |
if "GPU quota" in error_message:
|
285 |
error_message = "⚠️ GPU quota exceeded. Please try again later when the daily quota resets."
|
286 |
-
yield
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
|
294 |
# Update the CSS for better contrast and readability
|
295 |
css = """
|
|
|
223 |
print(f"Error generating speech: {str(e)}")
|
224 |
return None
|
225 |
|
226 |
+
def process_query(query: str, history: List[List[str]], selected_voice: str = 'af'):
|
227 |
"""Process user query with streaming effect"""
|
228 |
try:
|
229 |
if history is None:
|
|
|
235 |
|
236 |
current_history = history + [[query, "*Searching...*"]]
|
237 |
|
238 |
+
# Yield initial searching state
|
239 |
+
yield (
|
240 |
+
"*Searching & Thinking...*", # answer_output (Markdown)
|
241 |
+
sources_html, # sources_output (HTML)
|
242 |
+
"Searching...", # search_btn (Button)
|
243 |
+
current_history, # chat_history_display (Chatbot)
|
244 |
+
None # audio_output (Audio)
|
245 |
+
)
|
246 |
|
247 |
# Generate answer
|
248 |
prompt = format_prompt(query, web_results)
|
|
|
254 |
|
255 |
# Generate speech from the answer (only if enabled)
|
256 |
if TTS_ENABLED:
|
257 |
+
yield (
|
258 |
+
final_answer, # answer_output
|
259 |
+
sources_html, # sources_output
|
260 |
+
"Generating audio...", # search_btn
|
261 |
+
updated_history, # chat_history_display
|
262 |
+
None # audio_output
|
263 |
+
)
|
264 |
try:
|
265 |
audio = generate_speech_with_gpu(final_answer, selected_voice)
|
266 |
if audio is None:
|
|
|
272 |
final_answer += "\n\n*TTS is disabled. Audio not available.*"
|
273 |
audio = None
|
274 |
|
275 |
+
# Yield final result
|
276 |
+
yield (
|
277 |
+
final_answer, # answer_output
|
278 |
+
sources_html, # sources_output
|
279 |
+
"Search", # search_btn
|
280 |
+
updated_history, # chat_history_display
|
281 |
+
audio if audio is not None else None # audio_output
|
282 |
+
)
|
283 |
|
284 |
except Exception as e:
|
285 |
error_message = str(e)
|
286 |
if "GPU quota" in error_message:
|
287 |
error_message = "⚠️ GPU quota exceeded. Please try again later when the daily quota resets."
|
288 |
+
yield (
|
289 |
+
f"Error: {error_message}", # answer_output
|
290 |
+
sources_html, # sources_output
|
291 |
+
"Search", # search_btn
|
292 |
+
history + [[query, f"*Error: {error_message}*"]], # chat_history_display
|
293 |
+
None # audio_output
|
294 |
+
)
|
295 |
|
296 |
# Update the CSS for better contrast and readability
|
297 |
css = """
|