File size: 1,042 Bytes
0cf9dfe
afc4964
0cf9dfe
78ae545
 
0cf9dfe
78ae545
1957db6
0cf9dfe
78ae545
 
 
 
 
e06d02f
afc4964
e06d02f
 
afc4964
 
 
 
e06d02f
 
 
 
 
 
afc4964
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import streamlit as st
import requests

# # Print out all secrets to check what is available
# st.write(st.secrets)

# # Access the secret with the key "CTP_DATASCIENCE" (if that's how you've stored it)
CTP_DATASCIENCE = st.secrets.get("CTP_DATASCIENCE")

# # Check if the API key is available
# if CTP_DATASCIENCE:
#     st.success("API key found!")
# else:
#     st.error("API key not found!")

# Set up the headers for the Hugging Face API request using the API key
headers = {"Authorization": f"Bearer {CTP_DATASCIENCE}"}

# Define the Hugging Face API URL (for Whisper model, in this case)
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"

# Function to make the API request with the given file
def query(filename):
    with open(filename, "rb") as f:
        data = f.read()
    response = requests.post(API_URL, headers=headers, data=data)
    return response.json()

# Example usage with a sample audio file
output = query("sample1.flac")

# Display the output of the API request
st.write(output)