Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
-
#
|
5 |
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
# Funkcja
|
9 |
def transcribe(audio):
|
10 |
try:
|
11 |
-
print(f"
|
12 |
-
|
|
|
13 |
return result['text']
|
14 |
except Exception as e:
|
15 |
-
|
16 |
-
return f"Wystąpił błąd: {e}"
|
17 |
|
18 |
-
|
19 |
-
# Tworzenie interfejsu Gradio
|
20 |
iface = gr.Interface(
|
21 |
-
fn=transcribe,
|
22 |
-
inputs=gr.Audio(sources=["upload"], type="filepath"),
|
23 |
-
outputs="text",
|
24 |
-
title="Whisper
|
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()
|