sachin commited on
Commit ·
6bd1511
1
Parent(s): fafc659
init
Browse files- app.py +53 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
import dwani
|
| 5 |
+
|
| 6 |
+
# List of supported languages
|
| 7 |
+
LANGUAGES = ["malayalam", "tamil", "telugu", "hindi", "kannada"]
|
| 8 |
+
dwani.api_key = os.getenv("DWANI_API_KEY")
|
| 9 |
+
|
| 10 |
+
dwani.api_base = os.getenv("DWANI_API_BASE_URL")
|
| 11 |
+
|
| 12 |
+
# Function to extract language name
|
| 13 |
+
def get_lang_name(lang_string):
|
| 14 |
+
return lang_string.split("(")[0].strip().lower()
|
| 15 |
+
|
| 16 |
+
def transcribe_api(audio_file, language):
|
| 17 |
+
# Get the base URL from environment variable
|
| 18 |
+
result = dwani.ASR.transcribe(file_path=audio_file, language=language)
|
| 19 |
+
return result
|
| 20 |
+
|
| 21 |
+
# Create Gradio interface
|
| 22 |
+
with gr.Blocks(title="Speech to Text API Interface") as demo:
|
| 23 |
+
gr.Markdown("# Speech to Text API Interface")
|
| 24 |
+
|
| 25 |
+
with gr.Row():
|
| 26 |
+
with gr.Column():
|
| 27 |
+
# Input components
|
| 28 |
+
audio_input = gr.Audio(
|
| 29 |
+
label="Audio File",
|
| 30 |
+
type="filepath",
|
| 31 |
+
sources=["upload"]
|
| 32 |
+
)
|
| 33 |
+
language_input = gr.Dropdown(
|
| 34 |
+
label="Language",
|
| 35 |
+
choices=LANGUAGES,
|
| 36 |
+
value="kannada"
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
submit_btn = gr.Button("Transcribe")
|
| 40 |
+
|
| 41 |
+
with gr.Column():
|
| 42 |
+
# Output component
|
| 43 |
+
output = gr.JSON(label="Transcription Response")
|
| 44 |
+
|
| 45 |
+
# Connect the button click to the API function
|
| 46 |
+
submit_btn.click(
|
| 47 |
+
fn=transcribe_api,
|
| 48 |
+
inputs=[audio_input, language_input],
|
| 49 |
+
outputs=output
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
# Launch the interface
|
| 53 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
dwani
|