syedmudassir16 commited on
Commit
f39012c
·
verified ·
1 Parent(s): 534fcc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -10
app.py CHANGED
@@ -10,8 +10,6 @@ client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.1")
10
  # Initialize the ASR pipeline
11
  asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
12
 
13
- INITIAL_MESSAGE = "Hi! I'm your music buddy—tell me about your mood and the type of tunes you're in the mood for today!"
14
-
15
  def speech_to_text(speech):
16
  """Converts speech to text using the ASR pipeline."""
17
  return asr(speech)["text"]
@@ -66,6 +64,7 @@ def format_prompt(message, history):
66
 
67
  Note: if user asks something like i need a coffee then do not classify the mood directly and ask more follow-up questions as asked in examples.
68
 
 
69
  """
70
  prompt = f"{fixed_prompt}\n"
71
  for user_prompt, bot_response in history:
@@ -94,9 +93,6 @@ async def generate_audio(history):
94
  return audio_path
95
  return None
96
 
97
- def init_chat():
98
- return [("", INITIAL_MESSAGE)], [("", INITIAL_MESSAGE)], None
99
-
100
  # Gradio interface setup
101
  with gr.Blocks() as demo:
102
  gr.Markdown("# Mood-Based Music Recommender with Continuous Voice Chat")
@@ -109,10 +105,7 @@ with gr.Blocks() as demo:
109
 
110
  with gr.Row():
111
  submit = gr.Button("Send")
112
- voice_input = gr.Audio(sources="microphone", type="filepath", label="Voice Input")
113
-
114
- # Initialize chat with greeting
115
- demo.load(init_chat, outputs=[state, chatbot, audio_output])
116
 
117
  # Handle text input
118
  msg.submit(process_input, inputs=[msg, state], outputs=[state, chatbot, msg, voice_input]).then(
@@ -134,4 +127,4 @@ with gr.Blocks() as demo:
134
  )
135
 
136
  if __name__ == "__main__":
137
- demo.launch()
 
10
  # Initialize the ASR pipeline
11
  asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
12
 
 
 
13
  def speech_to_text(speech):
14
  """Converts speech to text using the ASR pipeline."""
15
  return asr(speech)["text"]
 
64
 
65
  Note: if user asks something like i need a coffee then do not classify the mood directly and ask more follow-up questions as asked in examples.
66
 
67
+ [Examples omitted for brevity]
68
  """
69
  prompt = f"{fixed_prompt}\n"
70
  for user_prompt, bot_response in history:
 
93
  return audio_path
94
  return None
95
 
 
 
 
96
  # Gradio interface setup
97
  with gr.Blocks() as demo:
98
  gr.Markdown("# Mood-Based Music Recommender with Continuous Voice Chat")
 
105
 
106
  with gr.Row():
107
  submit = gr.Button("Send")
108
+ voice_input = gr.Audio(source="microphone", type="filepath", label="Voice Input")
 
 
 
109
 
110
  # Handle text input
111
  msg.submit(process_input, inputs=[msg, state], outputs=[state, chatbot, msg, voice_input]).then(
 
127
  )
128
 
129
  if __name__ == "__main__":
130
+ demo.launch(share=True)