yaoyugua commited on
Commit
aa480e2
·
1 Parent(s): 6e763fa
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
3
 
4
  """
5
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
@@ -15,9 +16,16 @@ def respond(
15
  temperature,
16
  top_p,
17
  ):
18
- # Here you could process the audio file if needed
19
- # For now, just returning our fixed response
20
- yield "Buang NB"
 
 
 
 
 
 
 
21
 
22
 
23
  """
@@ -26,7 +34,7 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
26
  demo = gr.ChatInterface(
27
  respond,
28
  chatbot=gr.Chatbot(),
29
- textbox=gr.Audio(source="microphone", type="filepath"), # Changed to Audio input
30
  additional_inputs=[
31
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
32
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ import whisper
4
 
5
  """
6
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
 
16
  temperature,
17
  top_p,
18
  ):
19
+ # Load whisper model (you might want to move this outside the function)
20
+ model = whisper.load_model("base")
21
+
22
+ # Transcribe the audio file
23
+ if audio is not None:
24
+ result = model.transcribe(audio)
25
+ transcribed_text = result["text"]
26
+ yield f"Transcribed: {transcribed_text}\nResponse: Buang NB"
27
+ else:
28
+ yield "No audio detected. Please try again."
29
 
30
 
31
  """
 
34
  demo = gr.ChatInterface(
35
  respond,
36
  chatbot=gr.Chatbot(),
37
+ textbox=gr.Audio(type="filepath"), # Removed 'source' parameter as it's not supported
38
  additional_inputs=[
39
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
40
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),