mrmuminov commited on
Commit
57bf973
1 Parent(s): cd1b752
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +26 -32
  3. requirements.txt +1 -0
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🔥
4
  colorFrom: pink
5
  colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 5.4.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
4
  colorFrom: pink
5
  colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: 3.38.0
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py CHANGED
@@ -18,14 +18,14 @@ device = 0 if torch.cuda.is_available() else "cpu"
18
  pipe = pipeline(
19
  task="automatic-speech-recognition",
20
  model=MODEL_NAME,
21
- chunk_length_s=15,
22
  device=device,
23
  )
24
 
25
 
26
  def transcribe(inputs, task):
27
  if inputs is None:
28
- raise gr.Error("Fayl tanlanmadi yoki yuklashad xatolik! Iltimos qaytadan urinib ko'ring.")
29
 
30
  text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
31
  return text
@@ -60,7 +60,7 @@ def download_yt_audio(yt_url, filename):
60
  if file_length_s > YT_LENGTH_LIMIT_S:
61
  yt_length_limit_hms = time.strftime("%HH:%MM:%SS", time.gmtime(YT_LENGTH_LIMIT_S))
62
  file_length_hms = time.strftime("%HH:%MM:%SS", time.gmtime(file_length_s))
63
- raise gr.Error(f"Maximum YouTube length is {yt_length_limit_hms}, got {file_length_hms} YouTube video.")
64
 
65
  ydl_opts = {"outtmpl": filename, "format": "worstvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"}
66
 
@@ -93,52 +93,46 @@ demo = gr.Blocks()
93
  mf_transcribe = gr.Interface(
94
  fn=transcribe,
95
  inputs=[
96
- gr.Audio(sources=["microphone"], type="filepath"),
97
- gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
98
  ],
99
  outputs="text",
100
- title="Whisper Uzbek: Transcribe Audio",
101
- description=(
102
- "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the OpenAI Whisper"
103
- f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
104
- " of arbitrary length."
105
- ),
106
- flagging_mode="never",
107
  )
108
 
109
  file_transcribe = gr.Interface(
110
  fn=transcribe,
111
  inputs=[
112
- gr.Audio(sources=["upload"], type="filepath", label="Audio file"),
113
- gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
114
  ],
115
  outputs="text",
116
- title="Whisper Uzbek: Transcribe Audio",
117
- description=(
118
- "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the OpenAI Whisper"
119
- f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
120
- " of arbitrary length."
121
- ),
122
- flagging_mode="never",
123
  )
124
 
125
  yt_transcribe = gr.Interface(
126
  fn=yt_transcribe,
127
  inputs=[
128
- gr.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
129
- gr.Radio(["transcribe", "translate"], label="Task", value="transcribe")
130
  ],
131
  outputs=["html", "text"],
132
- title="Whisper Uzbek: Transcribe YouTube",
133
- description=(
134
- "Transcribe long-form YouTube videos with the click of a button! Demo uses the OpenAI Whisper checkpoint"
135
- f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
136
- " arbitrary length."
137
- ),
138
- flagging_mode="never",
139
  )
140
 
141
  with demo:
142
- gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Microphone", "Audio file", "YouTube"])
143
 
144
- demo.launch()
 
18
  pipe = pipeline(
19
  task="automatic-speech-recognition",
20
  model=MODEL_NAME,
21
+ chunk_length_s=30,
22
  device=device,
23
  )
24
 
25
 
26
  def transcribe(inputs, task):
27
  if inputs is None:
28
+ raise gr.Error("Fayl yuklanmadi.")
29
 
30
  text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
31
  return text
 
60
  if file_length_s > YT_LENGTH_LIMIT_S:
61
  yt_length_limit_hms = time.strftime("%HH:%MM:%SS", time.gmtime(YT_LENGTH_LIMIT_S))
62
  file_length_hms = time.strftime("%HH:%MM:%SS", time.gmtime(file_length_s))
63
+ raise gr.Error(f"Youtube video limit {yt_length_limit_hms}, bu video uzunligi {file_length_hms}.")
64
 
65
  ydl_opts = {"outtmpl": filename, "format": "worstvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"}
66
 
 
93
  mf_transcribe = gr.Interface(
94
  fn=transcribe,
95
  inputs=[
96
+ gr.inputs.Audio(source="microphone", type="filepath", optional=True),
97
+ gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
98
  ],
99
  outputs="text",
100
+ layout="horizontal",
101
+ theme="huggingface",
102
+ title="Whisper Large V3 - O'zbek tili",
103
+ description="",
104
+ allow_flagging="never",
 
 
105
  )
106
 
107
  file_transcribe = gr.Interface(
108
  fn=transcribe,
109
  inputs=[
110
+ gr.inputs.Audio(source="upload", type="filepath", optional=True, label="Audio fayl"),
111
+ gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
112
  ],
113
  outputs="text",
114
+ layout="horizontal",
115
+ theme="huggingface",
116
+ title="Whisper Large V3 - O'zbek tili",
117
+ description="",
118
+ allow_flagging="never",
 
 
119
  )
120
 
121
  yt_transcribe = gr.Interface(
122
  fn=yt_transcribe,
123
  inputs=[
124
+ gr.inputs.Textbox(lines=1, placeholder="Youtbe video linkini tashlang", label="YouTube URL"),
125
+ gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe")
126
  ],
127
  outputs=["html", "text"],
128
+ layout="horizontal",
129
+ theme="huggingface",
130
+ title="Whisper Large V3 - O'zbek tili",
131
+ description="",
132
+ allow_flagging="never",
 
 
133
  )
134
 
135
  with demo:
136
+ gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Mikrofon", "Audio fayl", "YouTube"])
137
 
138
+ demo.launch(enable_queue=True)
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  transformers
2
  torch
3
  yt-dlp
 
 
1
  transformers
2
  torch
3
  yt-dlp
4
+ gradio==3.38.0