import streamlit as st import requests # Title of the app st.title("Whisper API Transcription Service") st.markdown("Upload an audio file (mp3, wav, or flac) and get transcription results.") # Prompt the user for their Hugging Face API key my_key = st.text_input('Enter your Hugging Face API Key', type='password') # API URL for Whisper model API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo" # Set up the headers with the provided API key headers = {"Authorization": f"Bearer {my_key}"} # Function to send the file to the API and get the transcription result def query(file_data): try: response = requests.post(API_URL, headers=headers, files={'file': file_data}) return response.json() except requests.exceptions.RequestException as e: return {"error": str(e)} # File uploader widget for audio files uploaded_files = st.file_uploader("Choose an audio file", type=["mp3", "wav", "flac"], accept_multiple_files=True) # Handle file uploads and process them if API key is provided if my_key: # Proceed only if the API key is provided if uploaded_files: results = {} for uploaded_file in uploaded_files: st.write(f"Processing file: {uploaded_file.name}") # Send the file to the Hugging Face API output = query(uploaded_file) # Store and display the result results[uploaded_file.name] = output # Show results for all files st.write("Results:") for file, result in results.items(): st.write(f"**Results for {file}:**") st.json(result) else: st.write("Please upload an audio file to transcribe.") else: st.write("Please enter your Hugging Face API key to proceed.")