aahmed10202 commited on
Commit
1b704fc
1 Parent(s): 97d474b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -1,17 +1,14 @@
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
@@ -32,6 +29,14 @@ if my_key: # Proceed only if the API key is provided
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
 
@@ -47,4 +52,3 @@ if my_key: # Proceed only if the API key is provided
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
-
 
1
  import streamlit as st
2
  import requests
3
+ import io
4
 
5
+ # Hugging Face API setup
6
+ API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
 
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
+ # Set up headers with the provided API key
 
 
 
12
  headers = {"Authorization": f"Bearer {my_key}"}
13
 
14
  # Function to send the file to the API and get the transcription result
 
29
  for uploaded_file in uploaded_files:
30
  st.write(f"Processing file: {uploaded_file.name}")
31
 
32
+ # Validate file type and check if it's in the correct format
33
+ file_type = uploaded_file.type
34
+ st.write(f"File type: {file_type}")
35
+
36
+ if file_type not in ["audio/mpeg", "audio/wav", "audio/flac"]:
37
+ st.write(f"Unsupported file type: {file_type}. Please upload an MP3, WAV, or FLAC file.")
38
+ continue
39
+
40
  # Send the file to the Hugging Face API
41
  output = query(uploaded_file)
42
 
 
52
  st.write("Please upload an audio file to transcribe.")
53
  else:
54
  st.write("Please enter your Hugging Face API key to proceed.")