File size: 1,106 Bytes
ccabf63
6b694b5
163138e
5b29361
6b694b5
337a446
1620753
ccabf63
163138e
 
 
1620753
163138e
ccabf63
163138e
ccabf63
 
163138e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 streamlit as st
import requests
import os

API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
headers = {"Authorization": f"Bearer {st.secrets['HF_API_KEY']}"}

def query(file):
    data = file.read()
    response = requests.post(API_URL, headers=headers, data=data)
    return response.json()

st.title("Speech Recognition with Whisper")

uploaded_file = st.file_uploader("Choose an audio file", type=['wav', 'mp3', 'flac'])

if uploaded_file is not None:
    st.audio(uploaded_file, format='audio/wav')
    
    if st.button('Transcribe'):
        with st.spinner('Transcribing...'):
            result = query(uploaded_file)
            
            if 'text' in result:
                st.success("Transcription completed!")
                st.write("Transcribed text:")
                st.write(result['text'])
            else:
                st.error("An error occurred during transcription.")
                st.write("Error details:")
                st.write(result)

st.markdown("---")
st.write("Note: This app uses the Whisper API from Hugging Face.")