Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,34 @@
|
|
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":
|
6 |
|
7 |
def query(file):
|
8 |
-
|
9 |
-
|
10 |
-
|
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("
|
19 |
|
20 |
if uploaded_file is not None:
|
21 |
-
|
22 |
-
|
23 |
-
if
|
24 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
+
import os
|
4 |
|
5 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
6 |
+
headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
7 |
|
8 |
def query(file):
|
9 |
+
data = file.read()
|
10 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
11 |
+
return response.json()
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
st.title("Speech Recognition with Whisper")
|
14 |
|
15 |
+
uploaded_file = st.file_uploader("Choose an audio file", type=['wav', 'mp3', 'flac'])
|
16 |
|
17 |
if uploaded_file is not None:
|
18 |
+
st.audio(uploaded_file, format='audio/wav')
|
19 |
+
|
20 |
+
if st.button('Transcribe'):
|
21 |
+
with st.spinner('Transcribing...'):
|
22 |
+
result = query(uploaded_file)
|
23 |
+
|
24 |
+
if 'text' in result:
|
25 |
+
st.success("Transcription completed!")
|
26 |
+
st.write("Transcribed text:")
|
27 |
+
st.write(result['text'])
|
28 |
+
else:
|
29 |
+
st.error("An error occurred during transcription.")
|
30 |
+
st.write("Error details:")
|
31 |
+
st.write(result)
|
32 |
+
|
33 |
+
st.markdown("---")
|
34 |
+
st.write("Note: This app uses the Whisper API from Hugging Face.")
|