Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,24 @@
|
|
|
|
1 |
import requests
|
2 |
|
3 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
4 |
-
headers = {"Authorization": "Bearer
|
5 |
|
6 |
-
def query(
|
7 |
-
|
8 |
-
|
9 |
-
response
|
10 |
-
return response.json()
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
import requests
|
3 |
|
4 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
5 |
+
headers = {"Authorization": f"Bearer {st.secrets['HF_API_KEY']}"} # Безопасное хранение токена
|
6 |
|
7 |
+
def query(file):
|
8 |
+
try:
|
9 |
+
response = requests.post(API_URL, headers=headers, data=file.read())
|
10 |
+
response.raise_for_status() # Проверка на ошибки HTTP
|
11 |
+
return response.json()
|
12 |
+
except requests.exceptions.RequestException as e:
|
13 |
+
st.error(f"Ошибка запроса к API: {e}")
|
14 |
+
return None
|
15 |
|
16 |
+
st.title("Транскрипция аудио")
|
17 |
+
|
18 |
+
uploaded_file = st.file_uploader("Загрузите аудиофайл", type=["wav", "mp3", "flac"])
|
19 |
+
|
20 |
+
if uploaded_file is not None:
|
21 |
+
with st.spinner("Транскрибируется..."):
|
22 |
+
output = query(uploaded_file)
|
23 |
+
if output:
|
24 |
+
st.text_area("Транскрипт:", value=output["text"])
|