Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
from gradio_client import Client
|
3 |
+
asr_pipe = pipeline("automatic-speech-recognition", model="Abdullah17/whisper-small-urdu")
|
4 |
+
|
5 |
+
def transcribe_the_command(audio):
|
6 |
+
import soundfile as sf
|
7 |
+
sample_rate, audio_data = audio
|
8 |
+
file_name = "recorded_audio.wav"
|
9 |
+
sf.write(file_name, audio_data, sample_rate)
|
10 |
+
# Convert stereo to mono by averaging the two channels
|
11 |
+
print(file_name)
|
12 |
+
|
13 |
+
transcript = asr_pipe(file_name)["text"]
|
14 |
+
client = Client("https://ysharma-explore-llamav2-with-tgi.hf.space/")
|
15 |
+
result = client.predict(
|
16 |
+
"tell me a story",
|
17 |
+
api_name="/chat"
|
18 |
+
)
|
19 |
+
|
20 |
+
return result
|
21 |
+
# get_text_from_voice("urdu.wav")
|
22 |
+
import gradio as gr
|
23 |
+
|
24 |
+
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=transcribe_the_command,
|
27 |
+
inputs=gr.inputs.Audio(label="Recorded Audio",source="microphone"),
|
28 |
+
outputs="text",
|
29 |
+
title="Whisper Small Urdu Command",
|
30 |
+
description="Realtime demo for Urdu speech recognition using a fine-tuned Whisper small model and outputting the estimated command on the basis of speech transcript.",
|
31 |
+
)
|
32 |
+
|
33 |
+
iface.launch()
|