Sangmin commited on
Commit
18ea2dd
1 Parent(s): c5012b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -31,11 +31,14 @@ def chunks_to_srt(chunks):
31
  srt_format += f"{i}\n{start_time_hms} --> {end_time_hms}\n{chunk['text']}\n\n"
32
  return srt_format
33
 
34
- def transcribe(inputs, task, return_timestamps):
35
  if inputs is None:
36
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
37
-
38
- result = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=return_timestamps)
 
 
 
39
 
40
  if return_timestamps:
41
  return chunks_to_srt(result['chunks'])
@@ -135,6 +138,7 @@ file_transcribe = gr.Interface(
135
  gr.inputs.Audio(source="upload", type="filepath", optional=True, label="Audio file"),
136
  gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
137
  gr.inputs.Checkbox(label="Return timestamps"),
 
138
  ],
139
  outputs="text",
140
  layout="horizontal",
@@ -154,6 +158,7 @@ yt_transcribe = gr.Interface(
154
  gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
155
  gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
156
  gr.inputs.Checkbox(label="Return timestamps"),
 
157
  ],
158
  outputs=["html", "text"],
159
  layout="horizontal",
 
31
  srt_format += f"{i}\n{start_time_hms} --> {end_time_hms}\n{chunk['text']}\n\n"
32
  return srt_format
33
 
34
+ def transcribe(inputs, task, language, return_timestamps):
35
  if inputs is None:
36
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
37
+
38
+ # Map the language names to their corresponding codes
39
+ language_codes = {"English": "en", "Korean": "ko", "Japanese": "ja"}
40
+ language_code = language_codes.get(language, "en") # Default to "en" if the language is not found
41
+ result = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task, "language": f"<|{language_code}|>"}, return_timestamps=return_timestamps)
42
 
43
  if return_timestamps:
44
  return chunks_to_srt(result['chunks'])
 
138
  gr.inputs.Audio(source="upload", type="filepath", optional=True, label="Audio file"),
139
  gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
140
  gr.inputs.Checkbox(label="Return timestamps"),
141
+ gr.inputs.Dropdown(choices=["English", "Korean", "Japanese"], label="Language"),
142
  ],
143
  outputs="text",
144
  layout="horizontal",
 
158
  gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
159
  gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
160
  gr.inputs.Checkbox(label="Return timestamps"),
161
+ gr.inputs.Dropdown(choices=["English", "Korean", "Japanese"], label="Language"),
162
  ],
163
  outputs=["html", "text"],
164
  layout="horizontal",