Spaces:
Sleeping
Sleeping
AndrewLam489
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,31 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
|
4 |
-
#
|
5 |
-
# st.write(st.secrets)
|
6 |
-
|
7 |
-
# # Access the secret with the key "CTP_DATASCIENCE" (if that's how you've stored it)
|
8 |
CTP_DATASCIENCE = st.secrets.get("CTP_DATASCIENCE")
|
9 |
|
10 |
-
# # Check if the API key is available
|
11 |
-
# if CTP_DATASCIENCE:
|
12 |
-
# st.success("API key found!")
|
13 |
-
# else:
|
14 |
-
# st.error("API key not found!")
|
15 |
-
|
16 |
# Set up the headers for the Hugging Face API request using the API key
|
17 |
headers = {"Authorization": f"Bearer {CTP_DATASCIENCE}"}
|
18 |
|
19 |
# Define the Hugging Face API URL (for Whisper model, in this case)
|
20 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
21 |
|
22 |
-
# Function to make the API request with the given file
|
23 |
-
def query(
|
24 |
-
|
25 |
-
|
26 |
-
response
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# Display the output of the API request
|
33 |
st.write(output)
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
|
4 |
+
# Access the Hugging Face API key from the secrets
|
|
|
|
|
|
|
5 |
CTP_DATASCIENCE = st.secrets.get("CTP_DATASCIENCE")
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# Set up the headers for the Hugging Face API request using the API key
|
8 |
headers = {"Authorization": f"Bearer {CTP_DATASCIENCE}"}
|
9 |
|
10 |
# Define the Hugging Face API URL (for Whisper model, in this case)
|
11 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
12 |
|
13 |
+
# Function to make the API request with the given file URL
|
14 |
+
def query(file_url):
|
15 |
+
# Download the audio file from the Hugging Face Space URL
|
16 |
+
response = requests.get(file_url)
|
17 |
+
if response.status_code == 200:
|
18 |
+
# Send the file data to the Hugging Face API
|
19 |
+
response_api = requests.post(API_URL, headers=headers, data=response.content)
|
20 |
+
return response_api.json()
|
21 |
+
else:
|
22 |
+
return {"error": "Failed to download the file."}
|
23 |
+
|
24 |
+
# URL to your audio file on Hugging Face Space
|
25 |
+
file_url = "https://huggingface.co/spaces/AndrewLam489/PillID_Transcribe/resolve/main/Greenpill.m4a"
|
26 |
+
|
27 |
+
# Call the function with the audio file URL
|
28 |
+
output = query(file_url)
|
29 |
|
30 |
# Display the output of the API request
|
31 |
st.write(output)
|