Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
-
asr_pipeline = pipeline(
|
|
|
|
|
|
|
6 |
|
7 |
-
#
|
8 |
-
def transcribe(
|
9 |
-
result = asr_pipeline(
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
# Gradio Interface
|
13 |
interface = gr.Interface(
|
14 |
fn=transcribe,
|
15 |
-
inputs=gr.Audio(type="
|
16 |
-
outputs=gr.Textbox(label="Transcription"),
|
17 |
-
title="
|
18 |
-
description="
|
19 |
)
|
20 |
|
21 |
interface.launch()
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Whisper pipeline (supports Hindi, Punjabi, etc.)
|
5 |
+
asr_pipeline = pipeline(
|
6 |
+
task="automatic-speech-recognition",
|
7 |
+
model="openai/whisper-small",
|
8 |
+
)
|
9 |
|
10 |
+
# Function to transcribe and detect language
|
11 |
+
def transcribe(audio_np, sample_rate):
|
12 |
+
result = asr_pipeline({
|
13 |
+
"array": audio_np,
|
14 |
+
"sampling_rate": sample_rate
|
15 |
+
})
|
16 |
+
text = result["text"]
|
17 |
+
lang = result.get("language", "unknown")
|
18 |
+
return f"Detected Language: {lang}\n\nTranscription:\n{text}"
|
19 |
|
20 |
+
# Gradio Interface
|
21 |
interface = gr.Interface(
|
22 |
fn=transcribe,
|
23 |
+
inputs=gr.Audio(type="numpy", label="Upload or Record Audio"), # FIXED
|
24 |
+
outputs=gr.Textbox(label="Detected Language & Transcription"),
|
25 |
+
title="Auto Language Detection - Whisper",
|
26 |
+
description="Upload or record Hindi or Punjabi audio. Whisper will auto-detect language and transcribe."
|
27 |
)
|
28 |
|
29 |
interface.launch()
|
30 |
+
|