Spaces:
Sleeping
Sleeping
aahmed10202
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,41 @@
|
|
1 |
-
|
2 |
-
!pip install transformers
|
3 |
-
|
4 |
from transformers import pipeline
|
5 |
-
|
6 |
-
from google.colab import files
|
7 |
-
uploaded = files.upload()
|
8 |
-
print(f"Uploaded files: {list(uploaded.keys())}")
|
9 |
-
|
10 |
-
from google.colab import userdata
|
11 |
-
my_key = userdata.get('key')
|
12 |
-
|
13 |
import requests
|
14 |
|
|
|
|
|
|
|
|
|
15 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
16 |
headers = {"Authorization": f"Bearer {my_key}"}
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
|
|
|
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import requests
|
4 |
|
5 |
+
# Get the Hugging Face API Key from the user
|
6 |
+
my_key = st.text_input('Enter your Hugging Face API Key', type='password')
|
7 |
+
|
8 |
+
# Set the API URL for Whisper model
|
9 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
10 |
headers = {"Authorization": f"Bearer {my_key}"}
|
11 |
|
12 |
+
# Function to send the file to the API and get the response
|
13 |
+
def query(filename, file_data):
|
14 |
+
response = requests.post(API_URL, headers=headers, files={'file': file_data})
|
15 |
+
return response.json()
|
16 |
+
|
17 |
+
# Streamlit UI elements for file upload
|
18 |
+
st.title("Whisper API Audio Transcription")
|
19 |
+
st.markdown("Upload an audio file and get transcription results")
|
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 uploaded_files:
|
25 |
+
results = {}
|
26 |
+
for uploaded_file in uploaded_files:
|
27 |
+
st.write(f"Processing file: {uploaded_file.name}")
|
28 |
+
|
29 |
+
# Send the file to Hugging Face API
|
30 |
+
output = query(uploaded_file.name, uploaded_file)
|
31 |
+
|
32 |
+
# Store the result
|
33 |
+
results[uploaded_file.name] = output
|
34 |
+
|
35 |
+
# Display the results
|
36 |
+
st.write("Results:")
|
37 |
+
for file, result in results.items():
|
38 |
+
st.write(f"**Results for {file}:**")
|
39 |
+
st.json(result)
|
40 |
+
else:
|
41 |
+
st.write("Please upload an audio file.")
|