Update app.py
Browse files
app.py
CHANGED
|
@@ -266,12 +266,14 @@ if prompt := st.chat_input("How can I help you today?"):
|
|
| 266 |
|
| 267 |
image = Image.open('/home/user/app/pdf2image/output.png')
|
| 268 |
st.image(image)
|
|
|
|
| 269 |
|
| 270 |
def generate_audio():
|
| 271 |
sound_file = BytesIO()
|
| 272 |
tts = gTTS(result['result'], lang='en')
|
| 273 |
tts.write_to_fp(sound_file)
|
| 274 |
st.audio(sound_file)
|
|
|
|
| 275 |
|
| 276 |
|
| 277 |
#st.button(':speaker:', type='primary',on_click=generate_audio)
|
|
@@ -300,22 +302,32 @@ if prompt := st.chat_input("How can I help you today?"):
|
|
| 300 |
# if on_ref:
|
| 301 |
# generate_pdf()
|
| 302 |
|
| 303 |
-
|
| 304 |
-
if
|
| 305 |
-
st.session_state.
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
|
| 320 |
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
| 321 |
|
|
|
|
| 266 |
|
| 267 |
image = Image.open('/home/user/app/pdf2image/output.png')
|
| 268 |
st.image(image)
|
| 269 |
+
st.session_state.image_displayed = True
|
| 270 |
|
| 271 |
def generate_audio():
|
| 272 |
sound_file = BytesIO()
|
| 273 |
tts = gTTS(result['result'], lang='en')
|
| 274 |
tts.write_to_fp(sound_file)
|
| 275 |
st.audio(sound_file)
|
| 276 |
+
st.session_state.sound_played = True
|
| 277 |
|
| 278 |
|
| 279 |
#st.button(':speaker:', type='primary',on_click=generate_audio)
|
|
|
|
| 302 |
# if on_ref:
|
| 303 |
# generate_pdf()
|
| 304 |
|
| 305 |
+
# Initialize session state variables
|
| 306 |
+
if "image_displayed" not in st.session_state:
|
| 307 |
+
st.session_state.image_displayed = False
|
| 308 |
+
if "sound_played" not in st.session_state:
|
| 309 |
+
st.session_state.sound_played = False
|
| 310 |
+
|
| 311 |
+
# Define functions to display the image and play the sound
|
| 312 |
+
# def display_image():
|
| 313 |
+
# st.image("image.png")
|
| 314 |
+
# st.session_state.image_displayed = True
|
| 315 |
+
|
| 316 |
+
# def play_sound():
|
| 317 |
+
# st.audio("sound.mp3")
|
| 318 |
+
# st.session_state.sound_played = True
|
| 319 |
+
|
| 320 |
+
# Create the two buttons
|
| 321 |
+
st.button("Display Image", on_click=generate_pdf)
|
| 322 |
+
st.button("Play Sound", on_click=generate_audio)
|
| 323 |
+
|
| 324 |
+
# Check if the image has been displayed and display it if it has not
|
| 325 |
+
if not st.session_state.image_displayed:
|
| 326 |
+
generate_pdf()
|
| 327 |
+
|
| 328 |
+
# Check if the sound has been played and play it if it has not
|
| 329 |
+
if not st.session_state.sound_played:
|
| 330 |
+
generate_audio()
|
| 331 |
|
| 332 |
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
| 333 |
|