File size: 1,689 Bytes
900ecc2
dda9597
125977e
 
fd8125a
3217ed0
dda9597
760bbe9
 
fd8125a
 
 
 
 
 
ce04af0
fd8125a
ce04af0
125977e
760bbe9
 
125977e
760bbe9
 
fd8125a
900ecc2
fd8125a
125977e
fd8125a
 
 
 
ce04af0
fd8125a
 
ce04af0
 
fd8125a
 
 
0048de5
fd8125a
 
 
 
 
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
40
41
42
43
44
45
46
47
import streamlit as st
import requests
from transformers import pipeline

# Hugging Face Whisper API endpoint
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"

# Function to send the audio file to the Hugging Face Whisper API
def query(file_data, my_key):
    headers = {"Authorization": f"Bearer {my_key}"}
    response = requests.post(API_URL, headers=headers, data=file_data)
    if response.status_code == 200:
        return response.json()
    else:
        return {"error": response.text}

# Streamlit UI elements
st.title("Transcription App")
st.write("Upload one or more .wav, .mp3, or .flac audio files, and get the transcription.")

# Get the user's Hugging Face API key
my_key = st.text_input("Enter your Hugging Face API Key", type="password")

# File uploader for audio files
uploaded_files = st.file_uploader("Choose audio file(s)", type=["mp3", "wav", "flac"], accept_multiple_files=True)

if my_key and uploaded_files:  # Proceed only if the API key is provided and files are uploaded
    st.write("Processing your files...")
    results = {}  # Store results for each file
    
    for uploaded_file in uploaded_files:
        file_data = uploaded_file.read()  # Read the file content
        
        st.write(f"Sending {uploaded_file.name} to API...")
        output = query(file_data, my_key)  # Send the file to the API
        
        # Store the result
        results[uploaded_file.name] = output
    
    # Display the results
    for file, result in results.items():
        st.write(f"### Results for `{file}`:")
        if "error" in result:
            st.error(result["error"])
        else:
            st.json(result)