Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from key import HF_ACCESS_TOKEN
|
| 4 |
+
import numpy as np
|
| 5 |
+
import io
|
| 6 |
+
import soundfile as sf
|
| 7 |
+
|
| 8 |
+
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3"
|
| 9 |
+
headers = {"Authorization": f"Bearer {HF_ACCESS_TOKEN}"}
|
| 10 |
+
|
| 11 |
+
def query(audio_data):
|
| 12 |
+
with io.BytesIO() as f:
|
| 13 |
+
sf.write(f, audio_data[1], audio_data[0], format='wav')
|
| 14 |
+
data = f.getvalue()
|
| 15 |
+
|
| 16 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
| 17 |
+
return response.json()['text']
|
| 18 |
+
|
| 19 |
+
def transcribe(audio_data):
|
| 20 |
+
global output_text
|
| 21 |
+
print("Received audio data:", audio_data)
|
| 22 |
+
|
| 23 |
+
if audio_data is None:
|
| 24 |
+
print("Audio data is None. Check the microphone and input configuration.")
|
| 25 |
+
return None
|
| 26 |
+
|
| 27 |
+
sr, y = audio_data
|
| 28 |
+
y = y.astype(np.float32)
|
| 29 |
+
y /= np.max(np.abs(y))
|
| 30 |
+
|
| 31 |
+
# Add your transcription logic here if needed
|
| 32 |
+
transcription = query(audio_data)
|
| 33 |
+
return transcription
|
| 34 |
+
|
| 35 |
+
dark_minimalist = gr.Theme.from_hub("Taithrah/Minimal")
|
| 36 |
+
|
| 37 |
+
iface = gr.Interface(theme=dark_minimalist,
|
| 38 |
+
fn=transcribe,
|
| 39 |
+
inputs=gr.Microphone(label="Speak into the microphone",),
|
| 40 |
+
outputs="text",
|
| 41 |
+
allow_flagging="never",
|
| 42 |
+
css="""
|
| 43 |
+
footer {
|
| 44 |
+
visibility: hidden;
|
| 45 |
+
}
|
| 46 |
+
"""
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
iface.launch()
|