Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -34,15 +34,23 @@ def save_and_play_audio(audio_recorder):
|
|
34 |
return filename
|
35 |
return None
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
st.title("Speech to Text")
|
38 |
st.write("Record your speech and get the text.")
|
39 |
|
40 |
-
|
41 |
-
audio_recorder
|
42 |
-
if
|
43 |
-
|
44 |
-
filename =
|
45 |
-
|
46 |
-
output = query(filename)
|
47 |
-
st.write("Transcription:")
|
48 |
-
st.write(output)
|
|
|
34 |
return filename
|
35 |
return None
|
36 |
|
37 |
+
def transcribe_audio(file_path):
|
38 |
+
API_URL = "https://tonpixzfvq3791u9.us-east-1.aws.endpoints.huggingface.cloud"
|
39 |
+
headers = {
|
40 |
+
"Authorization": f"Bearer {openai_key}",
|
41 |
+
}
|
42 |
+
with open(file_path, 'rb') as f:
|
43 |
+
data = {'file': f}
|
44 |
+
response = requests.post(API_URL, headers=headers, files=data)
|
45 |
+
if response.status_code == 200:
|
46 |
+
st.write(response.json())
|
47 |
+
|
48 |
st.title("Speech to Text")
|
49 |
st.write("Record your speech and get the text.")
|
50 |
|
51 |
+
# Audio, transcribe, GPT:
|
52 |
+
filename = save_and_play_audio(audio_recorder)
|
53 |
+
if filename is not None:
|
54 |
+
transcription = transcribe_audio(filename)
|
55 |
+
st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
56 |
+
filename = None
|
|
|
|
|
|