feat: Enable MCP

#1
by multimodalart HF Staff - opened
Files changed (1) hide show
  1. app.py +22 -3
app.py CHANGED
@@ -113,7 +113,26 @@ def audio_to_base64(data, rate=16000):
113
  return encoded_string
114
 
115
  def process_audio_rag(audio_file_path, query, chunk_length=30, use_openai=False, openai_key=None):
116
- """Main processing function"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  if not audio_file_path:
118
  return "Please upload an audio file", None, None
119
 
@@ -210,7 +229,7 @@ with gr.Blocks(title="AudioRAG Demo") as demo:
210
 
211
  gr.Examples(
212
  examples=[
213
- ["test.m4a", "Whos the podcast host?", 30],
214
  ],
215
  inputs=[audio_input, query_input, chunk_length]
216
  )
@@ -224,4 +243,4 @@ with gr.Blocks(title="AudioRAG Demo") as demo:
224
  if __name__ == "__main__":
225
  # Load model on startup
226
  load_model()
227
- demo.launch()
 
113
  return encoded_string
114
 
115
  def process_audio_rag(audio_file_path, query, chunk_length=30, use_openai=False, openai_key=None):
116
+ """
117
+ Main processing function for audio RAG (Retrieval-Augmented Generation).
118
+
119
+ This function takes an audio file, splits it into chunks, embeds each chunk,
120
+ searches for the most relevant chunks based on a query, and optionally generates
121
+ a textual answer using OpenAI's API.
122
+
123
+ Args:
124
+ audio_file_path (str): Path to the uploaded audio file.
125
+ query (str): Search query to find relevant audio chunks.
126
+ chunk_length (int): Length of each audio chunk in seconds. Defaults to 30.
127
+ use_openai (bool): Whether to use OpenAI API for answer generation. Defaults to False.
128
+ openai_key (str): OpenAI API key for generating textual answers. Defaults to None.
129
+
130
+ Returns:
131
+ tuple: A tuple containing:
132
+ - result_text (str): Text describing the search results and optional AI-generated answer.
133
+ - first_chunk_path (str): Path to the saved audio file of the top matching chunk.
134
+ - fig (matplotlib.figure.Figure): Matplotlib figure showing the waveform of the top chunk.
135
+ """
136
  if not audio_file_path:
137
  return "Please upload an audio file", None, None
138
 
 
229
 
230
  gr.Examples(
231
  examples=[
232
+ ["test.m4a", "Who's the podcast host?", 30],
233
  ],
234
  inputs=[audio_input, query_input, chunk_length]
235
  )
 
243
  if __name__ == "__main__":
244
  # Load model on startup
245
  load_model()
246
+ demo.launch(mcp_server=True)