Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,50 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline
|
3 |
import requests
|
4 |
|
5 |
-
#
|
|
|
|
|
|
|
|
|
6 |
my_key = st.text_input('Enter your Hugging Face API Key', type='password')
|
7 |
|
8 |
-
#
|
9 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
10 |
-
headers = {"Authorization": f"Bearer {my_key}"}
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
response = requests.post(API_URL, headers=headers, files={'file': file_data})
|
15 |
-
return response.json()
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
# File uploader widget
|
22 |
uploaded_files = st.file_uploader("Choose an audio file", type=["mp3", "wav", "flac"], accept_multiple_files=True)
|
23 |
|
24 |
-
if
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
st.write(
|
39 |
-
|
|
|
|
|
|
|
|
|
40 |
else:
|
41 |
-
st.write("Please
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import requests
|
3 |
|
4 |
+
# Title of the app
|
5 |
+
st.title("Whisper API Transcription Service")
|
6 |
+
st.markdown("Upload an audio file (mp3, wav, or flac) and get transcription results.")
|
7 |
+
|
8 |
+
# Prompt the user for their Hugging Face API key
|
9 |
my_key = st.text_input('Enter your Hugging Face API Key', type='password')
|
10 |
|
11 |
+
# API URL for Whisper model
|
12 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
|
|
13 |
|
14 |
+
# Set up the headers with the provided API key
|
15 |
+
headers = {"Authorization": f"Bearer {my_key}"}
|
|
|
|
|
16 |
|
17 |
+
# Function to send the file to the API and get the transcription result
|
18 |
+
def query(file_data):
|
19 |
+
try:
|
20 |
+
response = requests.post(API_URL, headers=headers, files={'file': file_data})
|
21 |
+
return response.json()
|
22 |
+
except requests.exceptions.RequestException as e:
|
23 |
+
return {"error": str(e)}
|
24 |
|
25 |
+
# File uploader widget for audio files
|
26 |
uploaded_files = st.file_uploader("Choose an audio file", type=["mp3", "wav", "flac"], accept_multiple_files=True)
|
27 |
|
28 |
+
# Handle file uploads and process them if API key is provided
|
29 |
+
if my_key: # Proceed only if the API key is provided
|
30 |
+
if uploaded_files:
|
31 |
+
results = {}
|
32 |
+
for uploaded_file in uploaded_files:
|
33 |
+
st.write(f"Processing file: {uploaded_file.name}")
|
34 |
+
|
35 |
+
# Send the file to the Hugging Face API
|
36 |
+
output = query(uploaded_file)
|
37 |
+
|
38 |
+
# Store and display the result
|
39 |
+
results[uploaded_file.name] = output
|
40 |
+
|
41 |
+
# Show results for all files
|
42 |
+
st.write("Results:")
|
43 |
+
for file, result in results.items():
|
44 |
+
st.write(f"**Results for {file}:**")
|
45 |
+
st.json(result)
|
46 |
+
else:
|
47 |
+
st.write("Please upload an audio file to transcribe.")
|
48 |
else:
|
49 |
+
st.write("Please enter your Hugging Face API key to proceed.")
|
50 |
+
|