AhmadHazem commited on
Commit
81d721d
·
1 Parent(s): 2eacd80
Files changed (1) hide show
  1. app.py +10 -27
app.py CHANGED
@@ -28,7 +28,7 @@ model_name_translate = "Helsinki-NLP/opus-mt-en-ar"
28
  tokenizer_translation = MarianTokenizer.from_pretrained(model_name_translate)
29
  model_translate = MarianMTModel.from_pretrained(model_name_translate)
30
 
31
-
32
  def translate(sentence):
33
  batch = tokenizer_translation([sentence], return_tensors="pt")
34
  generated_ids = model_translate.generate(batch["input_ids"])
@@ -108,14 +108,13 @@ mf_transcribe = gr.Interface(
108
  fn=transcribe,
109
  inputs=[
110
  gr.Audio(sources="microphone", type="filepath"),
111
- gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
112
  ],
113
  outputs="text",
114
- title="Whisper Large V3 Turbo: Transcribe Audio",
115
  description=(
116
- "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
117
- f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
118
- " of arbitrary length."
119
  ),
120
  allow_flagging="never",
121
  )
@@ -124,36 +123,20 @@ file_transcribe = gr.Interface(
124
  fn=transcribe,
125
  inputs=[
126
  gr.Audio(sources="upload", type="filepath", label="Audio file"),
127
- gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
128
  ],
129
  outputs="text",
130
- title="Whisper Large V3: Transcribe Audio",
131
  description=(
132
- "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
133
- f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
134
- " of arbitrary length."
135
  ),
136
  allow_flagging="never",
137
  )
138
 
139
- yt_transcribe = gr.Interface(
140
- fn=yt_transcribe,
141
- inputs=[
142
- gr.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
143
- gr.Radio(["transcribe", "translate"], label="Task", value="transcribe")
144
- ],
145
- outputs=["html", "text"],
146
- title="Whisper Large V3: Transcribe YouTube",
147
- description=(
148
- "Transcribe long-form YouTube videos with the click of a button! Demo uses the checkpoint"
149
- f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
150
- " arbitrary length."
151
- ),
152
- allow_flagging="never",
153
- )
154
 
155
  with demo:
156
- gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Microphone", "Audio file", "YouTube"])
157
 
158
  demo.queue().launch(ssr_mode=False)
159
 
 
28
  tokenizer_translation = MarianTokenizer.from_pretrained(model_name_translate)
29
  model_translate = MarianMTModel.from_pretrained(model_name_translate)
30
 
31
+ @spaces.GPU
32
  def translate(sentence):
33
  batch = tokenizer_translation([sentence], return_tensors="pt")
34
  generated_ids = model_translate.generate(batch["input_ids"])
 
108
  fn=transcribe,
109
  inputs=[
110
  gr.Audio(sources="microphone", type="filepath"),
111
+ gr.Radio(["translate"], label="Task", value="transcribe"),
112
  ],
113
  outputs="text",
114
+ title="Real-Time Speech Translation From English to Arabic",
115
  description=(
116
+ "Real Time Speech Translation Model from English to Arabic. This model uses the Whisper For speech to generation"
117
+ "then Helensiki model fine tuned on a translation dataset for translation"
 
118
  ),
119
  allow_flagging="never",
120
  )
 
123
  fn=transcribe,
124
  inputs=[
125
  gr.Audio(sources="upload", type="filepath", label="Audio file"),
126
+ gr.Radio(["translate"], label="Task", value="transcribe"),
127
  ],
128
  outputs="text",
129
+ title="Real-Time Speech Translation From English to Arabic",
130
  description=(
131
+ "Real Time Speech Translation Model from English to Arabic. This model uses the Whisper For speech to generation"
132
+ "then Helensiki model fine tuned on a translation dataset for translation"
 
133
  ),
134
  allow_flagging="never",
135
  )
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
  with demo:
139
+ gr.TabbedInterface([mf_transcribe, file_transcribe], ["Microphone", "Audio file"])
140
 
141
  demo.queue().launch(ssr_mode=False)
142