File size: 1,135 Bytes
25ca65d
d2d0553
6e17754
 
 
 
 
25ca65d
d2d0553
6e17754
 
 
d2d0553
 
 
6e17754
d2d0553
 
 
 
0166f6b
d2d0553
 
25ca65d
d2d0553
 
 
 
 
0166f6b
d2d0553
 
 
6e17754
d2d0553
6e17754
 
d2d0553
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import gradio as gr
import requests
import os

# Retrieve ASR API URL and Authorization Token from environment variables
ASR_API_URL = os.getenv('ASR_API_URL')
AUTH_TOKEN = os.getenv('AUTH_TOKEN')

def transcribe_audio(file):
    if not ASR_API_URL or not AUTH_TOKEN:
        return "Error: Missing ASR_API_URL or AUTH_TOKEN."

    # Prepare headers and data
    headers = {
        'accept': 'application/json',
        'Authorization': f'Bearer {AUTH_TOKEN}',
    }
    files = {
        'file': (file.name, file, 'audio/mpeg'),
    }

    # Send POST request
    response = requests.post(ASR_API_URL, headers=headers, files=files)

    # Check if response is successful
    if response.status_code == 200:
        return response.json().get("transcription", "No transcription returned.")
    else:
        return f"Error: {response.status_code}, {response.text}"

# Set up the Gradio interface
gr.Interface(
    fn=transcribe_audio,
    inputs=gr.Audio(type="file"),
    outputs="text",
    title="Gooya v1 Persian ASR Transcription",
    description="Upload an audio file in Persian, and this Model will transcribe it."
).launch()