Dmtlant commited on
Commit
ccabf63
1 Parent(s): 34f84c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
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 hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
5
 
6
- def query(filename):
7
- with open(filename, "rb") as f:
8
- data = f.read()
9
- response = requests.post(API_URL, headers=headers, data=data)
10
- return response.json()
 
 
 
11
 
12
- output = query("sample1.flac")
 
 
 
 
 
 
 
 
 
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"])