Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,6 @@ from datetime import datetime
|
|
6 |
from TTS.api import TTS
|
7 |
import whisper
|
8 |
from audio_recorder import record
|
9 |
-
import os
|
10 |
|
11 |
# Custom Streamlit app title and icon
|
12 |
st.set_page_config(
|
@@ -29,7 +28,7 @@ openai_key = ""
|
|
29 |
# Check if the toggle is on
|
30 |
if api_toggle:
|
31 |
# If the toggle is on, access the API key from secrets
|
32 |
-
openai_key =
|
33 |
openai.api_key = openai_key
|
34 |
else:
|
35 |
# If the toggle is off, allow the user to input the API key
|
@@ -142,36 +141,29 @@ for message in st.session_state.messages:
|
|
142 |
with st.chat_message(message["role"]):
|
143 |
st.markdown(message["content"])
|
144 |
|
145 |
-
system_text="""As a helpful, thoughtful, and wise IELTS instructor responsible for testing Speaking Part 1
|
146 |
-
|
147 |
-
1. It's essential to follow these guidelines:
|
148 |
- Give only original question for provided {subject}.
|
149 |
- Give one question at a time.
|
150 |
-
|
151 |
-
Question example:
|
152 |
{subject}: Work
|
153 |
What is your job?
|
154 |
Where do you work?
|
155 |
-
|
156 |
{subject}: Study
|
157 |
What do you study?
|
158 |
Where do you study that?
|
159 |
-
|
160 |
{subject}: Hometown
|
161 |
Do you live in a house or a flat?
|
162 |
How are the walls decorated?
|
163 |
-
|
164 |
-
2. After receiving the user's answer:
|
165 |
-
- Give critical assessment on Lexical Resource (a range of words and paraphrasing, collocations, avoiding errors)
|
166 |
-
- Give critical assessment on Grammar (range of sentence structures, grammar tenses, avoiding errors)
|
167 |
-
- Give 2 new vocabulary to enhance the user's answer.
|
168 |
-
- Give a short band 8.0 IETLS example answer.
|
169 |
-
|
170 |
Let's start the test."""
|
171 |
|
172 |
# User Input and AI Response
|
173 |
# For "Chat mode"
|
|
|
|
|
|
|
174 |
if user_input_type == "Chat":
|
|
|
175 |
if prompt := st.chat_input("What is up?"):
|
176 |
# System
|
177 |
st.session_state.messages.append({"role": "system", "content": system_text})
|
@@ -206,6 +198,7 @@ if user_input_type == "Chat":
|
|
206 |
st.audio(convert_2_speech(full_response))
|
207 |
|
208 |
elif user_input_type == "Record Audio":
|
|
|
209 |
# Record audio when the "Record Audio" button is clicked
|
210 |
if st.button("Record Audio"):
|
211 |
st.write("Recording... Please speak for 10 seconds.")
|
|
|
6 |
from TTS.api import TTS
|
7 |
import whisper
|
8 |
from audio_recorder import record
|
|
|
9 |
|
10 |
# Custom Streamlit app title and icon
|
11 |
st.set_page_config(
|
|
|
28 |
# Check if the toggle is on
|
29 |
if api_toggle:
|
30 |
# If the toggle is on, access the API key from secrets
|
31 |
+
openai_key = st.secrets["OPENAI_API_KEY"]
|
32 |
openai.api_key = openai_key
|
33 |
else:
|
34 |
# If the toggle is off, allow the user to input the API key
|
|
|
141 |
with st.chat_message(message["role"]):
|
142 |
st.markdown(message["content"])
|
143 |
|
144 |
+
system_text="""As a helpful, thoughtful, and wise IELTS instructor responsible for testing Speaking Part 1. The users will provide the {subject} they want to talk about.
|
145 |
+
It's important to follow these guidelines:
|
|
|
146 |
- Give only original question for provided {subject}.
|
147 |
- Give one question at a time.
|
148 |
+
For example:
|
|
|
149 |
{subject}: Work
|
150 |
What is your job?
|
151 |
Where do you work?
|
|
|
152 |
{subject}: Study
|
153 |
What do you study?
|
154 |
Where do you study that?
|
|
|
155 |
{subject}: Hometown
|
156 |
Do you live in a house or a flat?
|
157 |
How are the walls decorated?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
Let's start the test."""
|
159 |
|
160 |
# User Input and AI Response
|
161 |
# For "Chat mode"
|
162 |
+
# Use st.toggle to allow users to choose input type
|
163 |
+
# record_audio_input = st.toggle("Record Audio Input", value=False) # for toggle only
|
164 |
+
|
165 |
if user_input_type == "Chat":
|
166 |
+
# if not record_audio_input: # for toggle only
|
167 |
if prompt := st.chat_input("What is up?"):
|
168 |
# System
|
169 |
st.session_state.messages.append({"role": "system", "content": system_text})
|
|
|
198 |
st.audio(convert_2_speech(full_response))
|
199 |
|
200 |
elif user_input_type == "Record Audio":
|
201 |
+
# else: # for toggle only
|
202 |
# Record audio when the "Record Audio" button is clicked
|
203 |
if st.button("Record Audio"):
|
204 |
st.write("Recording... Please speak for 10 seconds.")
|