Update app.py
Browse files138 unmodified lines13914014114214314414524 unmodified lines17017117217317417519 unmodified lines19519619719819920020120220312 unmodified lines2162172182192202212222238 unmodified lines23223323423523623723839 unmodified lines2782792802812822832842854 unmodified lines290291292293294295296297298299300138 unmodified linesreturn f"Error: {str(e)}"def process_audio_stream(audio_path, question_text=None):"""Streaming pipeline for Gradio UI"""start_time = time.time()# Step 1: Transcribe audio if provided24 unmodified linescurrent_time = time.time() - start_timetime_emoji = "🟢" if current_time < 3.0 else "🟡" if current_time < 3.5 else "🔴"timing_info = f"\n\n{time_emoji} **Timing:** Trans={transcription_time:.2f}s | Search={search_time:.2f}s | LLM={(time.time()-llm_start):.2f}s | **Total={current_time:.2f}s**"yield partial_answer + timing_info, current_time# Create Gradio interface19 unmodified linesaudio_output = gr.Textbox(label="Answer (Streaming)", lines=8, show_copy_button=True)audio_time = gr.Number(label="Response Time (seconds)", precision=2)audio_submit.click(fn=lambda x: process_audio_stream(x, None),inputs=[audio_input],outputs=[audio_output, audio_time],api_name="audio_query_stream")12 unmodified linestext_output = gr.Textbox(label="Answer (Streaming)", lines=8, show_copy_button=True)text_time = gr.Number(label="Response Time (seconds)", precision=2)text_submit.click(fn=lambda x: process_audio_stream(None, x),inputs=[text_input],outputs=[text_output, text_time],api_name="text_query_stream"8 unmodified linesinputs=text_input)# API endpoints for Pluely - Using Gradio's built-in interface functionswith gr.Tab("🔌 Pluely Integration"):gr.Markdown("""## Dedicated Endpoints for Pluely39 unmodified lineswith gr.Row(visible=False):stt_input = gr.Textbox()stt_output = gr.JSON()ai_input = gr.Textbox()ai_output = gr.Textbox()# These create the /call/transcribe_stt and /call/answer_ai_stream endpointsstt_button = gr.Button("STT", visible=False)4 unmodified linesapi_name="transcribe_stt")ai_button = gr.Button("AI", visible=False)ai_button.click(fn=generate_answer_stream,inputs=[ai_input],outputs=[ai_output],api_name="answer_ai_stream")138 unmodified lines13914014114214314414524 unmodified lines17017117217317417517619 unmodified lines19619719819920020120220320420512 unmodified lines2182192202212222232242252268 unmodified lines23523623723823924024139 unmodified lines2812822832842852862872884 unmodified lines293294295296297298299300301302303138 unmodified linesreturn f"Error: {str(e)}"def process_audio_stream(audio_path, question_text=None):"""Streaming pipeline for Gradio UI - Returns tuple generator"""start_time = time.time()# Step 1: Transcribe audio if provided24 unmodified linescurrent_time = time.time() - start_timetime_emoji = "🟢" if current_time < 3.0 else "🟡" if current_time < 3.5 else "🔴"timing_info = f"\n\n{time_emoji} **Timing:** Trans={transcription_time:.2f}s | Search={search_time:.2f}s | LLM={(time.time()-llm_start):.2f}s | **Total={current_time:.2f}s**"# IMPORTANT: Must yield tuple (text, number) to match output componentsyield partial_answer + timing_info, current_time# Create Gradio interface19 unmodified linesaudio_output = gr.Textbox(label="Answer (Streaming)", lines=8, show_copy_button=True)audio_time = gr.Number(label="Response Time (seconds)", precision=2)# Fixed: Lambda wrapper ensures proper tuple unpackingaudio_submit.click(fn=process_audio_stream,inputs=[audio_input, gr.Textbox(value=None, visible=False)],outputs=[audio_output, audio_time],api_name="audio_query_stream")12 unmodified linestext_output = gr.Textbox(label="Answer (Streaming)", lines=8, show_copy_button=True)text_time = gr.Number(label="Response Time (seconds)", precision=2)# Fixed: Proper function call with audio=Nonetext_submit.click(fn=lambda text: process_audio_stream(None, text),inputs=[text_input],outputs=[text_output, text_time],api_name="text_query_stream"8 unmodified linesinputs=text_input)# API endpoints for Pluelywith gr.Tab("🔌 Pluely Integration"):gr.Markdown("""## Dedicated Endpoints for Pluely39 unmodified lineswith gr.Row(visible=False):stt_input = gr.Textbox()stt_output = gr.JSON()ai_stream_input = gr.Textbox()ai_stream_output = gr.Textbox()# These create the /call/transcribe_stt and /call/answer_ai_stream endpointsstt_button = gr.Button("STT", visible=False)4 unmodified linesapi_name="transcribe_stt")ai_stream_button = gr.Button("AI Stream", visible=False)ai_stream_button.click(fn=generate_answer_stream,inputs=[ai_stream_input],outputs=[ai_stream_output],api_name="answer_ai_stream")
app.py+14-11