multimodalart HF Staff commited on
Commit
14495d1
·
verified ·
1 Parent(s): 7272785

feat: Enable MCP

Browse files

Hello! This is an automated PR adding MCP compatibility to your AI App 🤖.

![image.png](https://cdn-uploads.huggingface.co/production/uploads/624bebf604abc7ebb01789af/HQQK38I_MDXLDMYDYBq8H.png)This PR introduces two improvements:
1. Adds docstrings to the functions in the app file that are directly connected to the Gradio UI, for the downstream LLM to use.
2. Enables the Model-Compute-Platform by adding `mcp_server=True` to the `.launch()` call.

No other logic has been changed. Please review and merge if it looks good!Learn more about MCP compatibility in Spaces here: https://huggingface.co/changelog/add-compatible-spaces-to-your-mcp-tools

Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -19,6 +19,18 @@ generation_config_multi = model_multi.default_generation_config
19
  # MULTI-TURN INFERENCE FUNCTION
20
  # ---------------------------------
21
  def multi_turn_chat(user_input, audio_file, history, current_audio):
 
 
 
 
 
 
 
 
 
 
 
 
22
  try:
23
  if audio_file is not None:
24
  current_audio = audio_file # Update state if a new file is uploaded
@@ -37,6 +49,15 @@ def multi_turn_chat(user_input, audio_file, history, current_audio):
37
  history.append((user_input, f"❌ Error: {str(e)}"))
38
  return history, history, current_audio
39
  def speech_prompt_infer(audio_prompt_file):
 
 
 
 
 
 
 
 
 
40
  try:
41
  sound = llava.Sound(audio_prompt_file)
42
  full_prompt = "<sound>"
@@ -197,4 +218,4 @@ To enable these capabilities, we propose several large-scale training datasets c
197
  # Launch App
198
  # -----------------------
199
  if __name__ == "__main__":
200
- demo.launch(share=True)
 
19
  # MULTI-TURN INFERENCE FUNCTION
20
  # ---------------------------------
21
  def multi_turn_chat(user_input, audio_file, history, current_audio):
22
+ """
23
+ Handle multi-turn chat interactions with audio context.
24
+
25
+ Args:
26
+ user_input: The user's text message/question about the audio
27
+ audio_file: New audio file path if uploaded, otherwise None
28
+ history: List of previous conversation turns as (user_msg, bot_response) tuples
29
+ current_audio: Path to the currently active audio file in the conversation
30
+
31
+ Returns:
32
+ Tuple of (updated_chatbot_display, updated_history, updated_current_audio)
33
+ """
34
  try:
35
  if audio_file is not None:
36
  current_audio = audio_file # Update state if a new file is uploaded
 
49
  history.append((user_input, f"❌ Error: {str(e)}"))
50
  return history, history, current_audio
51
  def speech_prompt_infer(audio_prompt_file):
52
+ """
53
+ Process speech/audio input and generate a text response.
54
+
55
+ Args:
56
+ audio_prompt_file: Path to the audio file containing the user's speech prompt
57
+
58
+ Returns:
59
+ String containing the model's text response or error message
60
+ """
61
  try:
62
  sound = llava.Sound(audio_prompt_file)
63
  full_prompt = "<sound>"
 
218
  # Launch App
219
  # -----------------------
220
  if __name__ == "__main__":
221
+ demo.launch(share=True, mcp_server=True)