Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,18 @@ import os
|
|
6 |
from datetime import datetime
|
7 |
from audio_recorder_streamlit import audio_recorder
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
def generate_filename(prompt, file_type):
|
10 |
central = pytz.timezone('US/Central')
|
11 |
safe_date_time = datetime.now(central).strftime("%m%d_%H%M")
|
@@ -24,34 +36,10 @@ def save_and_play_audio(audio_recorder):
|
|
24 |
return filename
|
25 |
|
26 |
# 9B. Speech transcription to file output - OPENAI Whisper
|
27 |
-
def transcribe_audio(
|
28 |
-
|
29 |
-
|
30 |
-
"Authorization": f"Bearer {key}",
|
31 |
-
"Content-Type": "audio/wav"
|
32 |
-
}
|
33 |
-
with open(file_path, 'rb') as f:
|
34 |
-
data = {'file': f}
|
35 |
-
API_URL = "https://tonpixzfvq3791u9.us-east-1.aws.endpoints.huggingface.cloud"
|
36 |
-
response = requests.post(API_URL, headers=headers, data=data)
|
37 |
-
st.write(response)
|
38 |
-
|
39 |
-
if response.status_code == 200:
|
40 |
-
st.write('Reasoning with your transcription..')
|
41 |
-
try:
|
42 |
-
transcript=response.json().get('text')
|
43 |
-
except:
|
44 |
-
transcript=response
|
45 |
|
46 |
-
st.write(transcript)
|
47 |
-
#gptResponse = chat_with_model(transcript, systemPrompt=user_prompt_System, model=MODELCHOICE) # send transcript to ChatGPT - prompts, systemPrompt=SYSTEM_PROMPT, model="Gpt-4-32k"
|
48 |
-
#filename = generate_filename(transcript, choice)
|
49 |
-
#create_file(filename, transcript, gptResponse) # write output file
|
50 |
-
#return gptResponse
|
51 |
-
else:
|
52 |
-
#st.write(response.json())
|
53 |
-
#st.error("Error in API call.")
|
54 |
-
return None
|
55 |
|
56 |
def main():
|
57 |
st.title("Speech to Text")
|
@@ -61,8 +49,7 @@ def main():
|
|
61 |
filename = save_and_play_audio(audio_recorder)
|
62 |
if filename is not None:
|
63 |
transcription = transcribe_audio(filename)
|
64 |
-
|
65 |
-
filename = None
|
66 |
|
67 |
if __name__ == "__main__":
|
68 |
main()
|
|
|
6 |
from datetime import datetime
|
7 |
from audio_recorder_streamlit import audio_recorder
|
8 |
|
9 |
+
API_URL = f'https://tonpixzfvq3791u9.us-east-1.aws.endpoints.huggingface.cloud'
|
10 |
+
headers = {
|
11 |
+
"Authorization": "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
12 |
+
"Content-Type": "audio/wav"
|
13 |
+
}
|
14 |
+
|
15 |
+
def query(filename):
|
16 |
+
with open(filename, "rb") as f:
|
17 |
+
data = f.read()
|
18 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
19 |
+
return response.json()
|
20 |
+
|
21 |
def generate_filename(prompt, file_type):
|
22 |
central = pytz.timezone('US/Central')
|
23 |
safe_date_time = datetime.now(central).strftime("%m%d_%H%M")
|
|
|
36 |
return filename
|
37 |
|
38 |
# 9B. Speech transcription to file output - OPENAI Whisper
|
39 |
+
def transcribe_audio(filename):
|
40 |
+
output = query(filename)
|
41 |
+
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
def main():
|
45 |
st.title("Speech to Text")
|
|
|
49 |
filename = save_and_play_audio(audio_recorder)
|
50 |
if filename is not None:
|
51 |
transcription = transcribe_audio(filename)
|
52 |
+
st.write(transcription)
|
|
|
53 |
|
54 |
if __name__ == "__main__":
|
55 |
main()
|