tomekstor9 commited on
Commit
9da5321
·
verified ·
1 Parent(s): 42295c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -1,27 +1,34 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
3
 
4
- # Załadowanie modelu Whisper
5
  transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-small")
6
 
 
 
 
 
 
 
 
7
 
8
- # Funkcja do transkrypcji audio
9
  def transcribe(audio):
10
  try:
11
- print(f"Przetwarzanie pliku audio: {audio}") # Logowanie
12
- result = transcriber(audio)
 
13
  return result['text']
14
  except Exception as e:
15
- print(f"Błąd transkrypcji: {e}")
16
- return f"Wystąpił błąd: {e}"
17
 
18
-
19
- # Tworzenie interfejsu Gradio
20
  iface = gr.Interface(
21
- fn=transcribe, # Funkcja przetwarzająca plik audio
22
- inputs=gr.Audio(sources=["upload"], type="filepath"), # Wejście: plik audio
23
- outputs="text", # Wyjście: transkrypcja tekstowa
24
- title="Whisper Large V3 - Transkrypcja Audio"
25
  )
26
 
27
  iface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ from pydub import AudioSegment
4
 
5
+ # Załaduj mniejszy model Whisper
6
  transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-small")
7
 
8
+ # Funkcja konwersji audio do 16 kHz
9
+ def convert_audio(audio):
10
+ sound = AudioSegment.from_file(audio)
11
+ sound = sound.set_frame_rate(16000).set_channels(1)
12
+ temp_file = "converted.wav"
13
+ sound.export(temp_file, format="wav")
14
+ return temp_file
15
 
16
+ # Funkcja transkrypcji
17
  def transcribe(audio):
18
  try:
19
+ print(f"Konwersja pliku audio: {audio}")
20
+ converted_audio = convert_audio(audio) # Konwersja
21
+ result = transcriber(converted_audio)
22
  return result['text']
23
  except Exception as e:
24
+ return f"Błąd: {e}"
 
25
 
26
+ # Interfejs Gradio
 
27
  iface = gr.Interface(
28
+ fn=transcribe,
29
+ inputs=gr.Audio(sources=["upload"], type="filepath"),
30
+ outputs="text",
31
+ title="Whisper Small - Transkrypcja Audio"
32
  )
33
 
34
  iface.launch()