File size: 964 Bytes
1ecbd6e
161393d
59d8ead
161393d
 
 
0d5a69e
161393d
 
 
 
867943a
161393d
 
 
 
867943a
161393d
867943a
 
161393d
f9b726c
 
161393d
f9b726c
161393d
 
 
f9b726c
 
 
 
 
cd06e6a
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
import gradio as gr
import requests

API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v2/whisper"
API_KEY = "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"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

def transcribe_audio(audio_path: str) -> str:
    # Read audio file
    with open(audio_path, "rb") as f:
        audio_data = f.read()
    
    # Make API request to OpenAI Whisper v2 API
    response = requests.post(API_URL, headers=HEADERS, data=audio_data)
    result = response.json()
    transcribed_text = result["text"]
    
    return transcribed_text

audio_input = gr.inputs.Audio(type="filepath")
text_output = gr.outputs.Textbox()

iface = gr.Interface(
    fn=transcribe_audio,
    inputs=audio_input,
    outputs=text_output,
    title="Speech-to-Text using Whisper v2",
    description="Upload an audio file to transcribe it to text.",
    theme="Monochrome",
    live=True,
    capture_session=True,
)

iface.launch()