Edward Nagy commited on
Commit
f9bd2ea
·
unverified ·
1 Parent(s): 05d486c

Update transcribe function to handle input data

Browse files
Files changed (1) hide show
  1. app.py +15 -21
app.py CHANGED
@@ -7,13 +7,16 @@ import os
7
  # pipe = pipeline(model="esnagy/whisper-small-hu")
8
 
9
  def transcribe_audio(audio_file):
10
- text = "Test text"
11
  # text = pipe(audio_file)["text"]
12
  os.remove(audio_file) # Remove temporary audio file
13
  return text
14
 
15
- def transcribe(video_url, audio=None):
16
- if video_url:
 
 
 
17
  # Download the video from the URL
18
  video_filename = "temp_video.mp4"
19
  with open(video_filename, 'wb') as f:
@@ -35,24 +38,15 @@ def transcribe(video_url, audio=None):
35
 
36
  return text
37
 
38
- elif audio:
39
- return transcribe_audio(audio)
40
-
41
- iface_video = gr.Interface(
42
- fn=transcribe,
43
- inputs=gr.Textbox(label="Enter video URL", placeholder="Or leave empty to use microphone"),
44
- outputs="text",
45
- title="Whisper Small Hungarian - Video",
46
- description="Realtime demo for Hungarian speech recognition using a fine-tuned Whisper small model. Enter a video URL to transcribe its audio."
47
- )
48
-
49
- iface_audio = gr.Interface(
50
  fn=transcribe,
51
- inputs=gr.Audio(sources=["microphone"], type="filepath", label="Or record your voice"),
52
- outputs="text",
53
- title="Whisper Small Hungarian - Microphone",
54
- description="Realtime demo for Hungarian speech recognition using a fine-tuned Whisper small model. Record your voice to transcribe."
 
 
 
55
  )
56
 
57
- iface_video.launch(share=True)
58
- iface_audio.launch(share=True)
 
7
  # pipe = pipeline(model="esnagy/whisper-small-hu")
8
 
9
  def transcribe_audio(audio_file):
10
+ text = "Text text"
11
  # text = pipe(audio_file)["text"]
12
  os.remove(audio_file) # Remove temporary audio file
13
  return text
14
 
15
+ def transcribe(input_data):
16
+ if input_data["audio"]:
17
+ return transcribe_audio(input_data["audio"].name)
18
+ elif input_data["video_url"]:
19
+ video_url = input_data["video_url"]
20
  # Download the video from the URL
21
  video_filename = "temp_video.mp4"
22
  with open(video_filename, 'wb') as f:
 
38
 
39
  return text
40
 
41
+ iface = gr.Interface(
 
 
 
 
 
 
 
 
 
 
 
42
  fn=transcribe,
43
+ inputs=[
44
+ gr.Input("text", label="Enter video URL", name="video_url", placeholder="Or leave empty to use microphone"),
45
+ gr.Input("audio", label="Or record your voice", name="audio", source="microphone")
46
+ ],
47
+ outputs=gr.Output("text"),
48
+ title="Whisper Small Hungarian",
49
+ description="Realtime demo for Hungarian speech recognition using a fine-tuned Whisper small model. Enter a video URL or record your voice to transcribe."
50
  )
51
 
52
+ iface.launch()