|
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.") |