Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -30,31 +30,24 @@ def generate_filename(prompt, file_type):
|
|
30 |
safe_prompt = "".join(x for x in prompt if x.isalnum())[:45]
|
31 |
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
32 |
|
33 |
-
|
34 |
-
# Audio record and transcribe:
|
35 |
-
def transcribe_audio_ui(openai_key, file_path):
|
36 |
OPENAI_API_URL = "https://api.openai.com/v1/audio/transcriptions"
|
37 |
headers = {
|
38 |
"Authorization": f"Bearer {openai_key}",
|
39 |
-
"Content-Type": "multipart/form-data",
|
40 |
}
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
if file_path is not None:
|
55 |
-
if st.button("Transcribe"):
|
56 |
-
transcription = transcribe_audio(file_path, "whisper-1")
|
57 |
-
st.write(transcription)
|
58 |
|
59 |
def save_and_play_audio(audio_recorder):
|
60 |
audio_bytes = audio_recorder()
|
@@ -67,12 +60,10 @@ def save_and_play_audio(audio_recorder):
|
|
67 |
return None
|
68 |
|
69 |
filename = save_and_play_audio(audio_recorder)
|
70 |
-
if filename:
|
71 |
-
st.
|
72 |
-
|
73 |
-
|
74 |
-
st.write("No audio data was recorded")
|
75 |
-
|
76 |
|
77 |
def chat_with_model(prompt, document_section):
|
78 |
model = model_choice
|
|
|
30 |
safe_prompt = "".join(x for x in prompt if x.isalnum())[:45]
|
31 |
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
32 |
|
33 |
+
def transcribe_audio(openai_key, file_path, model):
|
|
|
|
|
34 |
OPENAI_API_URL = "https://api.openai.com/v1/audio/transcriptions"
|
35 |
headers = {
|
36 |
"Authorization": f"Bearer {openai_key}",
|
|
|
37 |
}
|
38 |
+
|
39 |
+
with open(file_path, 'rb') as f:
|
40 |
+
data = {'file': f}
|
41 |
+
response = requests.post(OPENAI_API_URL, headers=headers, files=data, data={'model': model})
|
42 |
+
|
43 |
+
if response.status_code == 200:
|
44 |
+
st.write(response.json())
|
45 |
+
return response.json().get('text')
|
46 |
+
else:
|
47 |
+
st.write(response.json())
|
48 |
+
st.error("Error in API call.")
|
49 |
+
return None
|
50 |
+
|
|
|
|
|
|
|
|
|
51 |
|
52 |
def save_and_play_audio(audio_recorder):
|
53 |
audio_bytes = audio_recorder()
|
|
|
60 |
return None
|
61 |
|
62 |
filename = save_and_play_audio(audio_recorder)
|
63 |
+
if filename is not None:
|
64 |
+
if st.button("Transcribe"):
|
65 |
+
transcription = transcribe_audio(openai_key, filename, "whisper-1")
|
66 |
+
st.write(transcription)
|
|
|
|
|
67 |
|
68 |
def chat_with_model(prompt, document_section):
|
69 |
model = model_choice
|