Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,36 +23,33 @@ my_key = st.text_input('Enter your Hugging Face API Key', type='password')
|
|
23 |
uploaded_files = st.file_uploader("Choose an audio file", type=["mp3", "wav", "flac"], accept_multiple_files=True)
|
24 |
|
25 |
if my_key: # Proceed only if the API key is provided
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
# Check the MIME type of the uploaded file
|
33 |
-
file_type = uploaded_file.type
|
34 |
-
st.write(f"File type: {file_type}")
|
35 |
-
|
36 |
-
# Validate file type (must be one of the supported types)
|
37 |
-
if file_type not in ["audio/mpeg", "audio/wav", "audio/flac"]:
|
38 |
-
st.write(f"Unsupported file type: {file_type}. Please upload an MP3, WAV, or FLAC file.")
|
39 |
-
continue
|
40 |
-
|
41 |
-
# Send the file to the Hugging Face API for transcription
|
42 |
-
output = query(uploaded_file, my_key)
|
43 |
-
|
44 |
-
# Store and display the result
|
45 |
-
results[uploaded_file.name] = output
|
46 |
|
47 |
-
#
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
st.write("Please enter your Hugging Face API key to proceed.")
|
57 |
|
58 |
|
|
|
23 |
uploaded_files = st.file_uploader("Choose an audio file", type=["mp3", "wav", "flac"], accept_multiple_files=True)
|
24 |
|
25 |
if my_key: # Proceed only if the API key is provided
|
26 |
+
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
27 |
+
headers = {"Authorization": f"Bearer {my_key}"}
|
28 |
+
|
29 |
+
def query(filename):
|
30 |
+
filename = list(uploaded.keys())[0] # Get the uploaded file's nameprint("Uploaded filename:", filename)
|
31 |
+
with open(filename, "rb") as f:
|
32 |
+
data = f.read()
|
33 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
34 |
+
return response.json()
|
35 |
+
|
36 |
+
results = {}
|
37 |
+
for filename, file_data in uploaded.items():
|
38 |
+
# Save the file locally
|
39 |
+
with open(filename, "wb") as f:
|
40 |
+
f.write(file_data)
|
41 |
|
42 |
+
print(f"Sending {filename} to API...")
|
43 |
+
output = query(filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
# Store the result
|
46 |
+
results[filename] = output
|
47 |
+
|
48 |
+
# Step 3: Print results
|
49 |
+
for file, result in results.items():
|
50 |
+
st.write(f"\nResults for {file}:\n{result}")
|
51 |
+
|
52 |
+
|
53 |
+
|
|
|
54 |
|
55 |
|