cigol123 commited on
Commit
12f2e01
·
verified ·
1 Parent(s): 8f0e28c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -6,8 +6,17 @@ import numpy as np
6
  from scipy import signal
7
  import os
8
 
9
- processor = WhisperProcessor.from_pretrained("openai/whisper-large-v3")
10
- model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large-v3")
 
 
 
 
 
 
 
 
 
11
 
12
  def process_audio(audio_path):
13
  waveform, sr = sf.read(audio_path)
@@ -21,14 +30,14 @@ def process_audio(audio_path):
21
  predicted_ids = model.generate(**inputs, language="mk")
22
  return processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
23
 
 
24
  demo = gr.Interface(
25
  fn=process_audio,
26
  inputs=gr.Audio(sources=["microphone", "upload"], type="filepath"),
27
  outputs="text",
28
  title="Македонско препознавање на говор / Macedonian Speech Recognition",
29
  description="Качете аудио или користете микрофон за транскрипција на македонски говор / Upload audio or use microphone to transcribe Macedonian speech",
30
- allow_flagging="manual",
31
- flagging_options=["Incorrect Transcription", "Good Transcription"]
32
  )
33
 
34
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
6
  from scipy import signal
7
  import os
8
 
9
+ # Set up directories
10
+ home_dir = os.path.expanduser("~")
11
+ cache_dir = os.path.join(home_dir, "cache")
12
+ flagged_dir = os.path.join(home_dir, "flagged")
13
+
14
+ # Configure cache
15
+ os.environ['TRANSFORMERS_CACHE'] = cache_dir
16
+ os.makedirs(cache_dir, exist_ok=True)
17
+
18
+ processor = WhisperProcessor.from_pretrained("openai/whisper-large-v3", cache_dir=cache_dir)
19
+ model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large-v3", cache_dir=cache_dir)
20
 
21
  def process_audio(audio_path):
22
  waveform, sr = sf.read(audio_path)
 
30
  predicted_ids = model.generate(**inputs, language="mk")
31
  return processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
32
 
33
+ # Create Gradio interface with custom flagging directory
34
  demo = gr.Interface(
35
  fn=process_audio,
36
  inputs=gr.Audio(sources=["microphone", "upload"], type="filepath"),
37
  outputs="text",
38
  title="Македонско препознавање на говор / Macedonian Speech Recognition",
39
  description="Качете аудио или користете микрофон за транскрипција на македонски говор / Upload audio or use microphone to transcribe Macedonian speech",
40
+ flagging_dir=flagged_dir
 
41
  )
42
 
43
  demo.launch(server_name="0.0.0.0", server_port=7860)