Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
from PIL import Image
|
|
|
|
|
|
|
| 3 |
import io
|
| 4 |
from openai import OpenAI
|
| 5 |
#from dotenv import load_dotenv
|
|
@@ -21,7 +23,7 @@ uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "pn
|
|
| 21 |
if 'history' not in st.session_state:
|
| 22 |
st.session_state['history'] = []
|
| 23 |
|
| 24 |
-
personality = st.text_input("Enter a personality
|
| 25 |
image_narration = "No narration given"
|
| 26 |
|
| 27 |
# Check if an image has been uploaded
|
|
@@ -61,5 +63,11 @@ def update_and_get_narration(personality, user_input):
|
|
| 61 |
if st.button('Narrate'):
|
| 62 |
narration = update_and_get_narration(personality, image_narration)
|
| 63 |
st.write(narration)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
else:
|
| 65 |
st.write(st.session_state['history'][-1]['content'] if st.session_state['history'] else "Narration will appear here.")
|
|
|
|
| 1 |
import os
|
| 2 |
from PIL import Image
|
| 3 |
+
from gtts import gTTS
|
| 4 |
+
from io import BytesIO
|
| 5 |
import io
|
| 6 |
from openai import OpenAI
|
| 7 |
#from dotenv import load_dotenv
|
|
|
|
| 23 |
if 'history' not in st.session_state:
|
| 24 |
st.session_state['history'] = []
|
| 25 |
|
| 26 |
+
personality = st.text_input("Enter a personality")
|
| 27 |
image_narration = "No narration given"
|
| 28 |
|
| 29 |
# Check if an image has been uploaded
|
|
|
|
| 63 |
if st.button('Narrate'):
|
| 64 |
narration = update_and_get_narration(personality, image_narration)
|
| 65 |
st.write(narration)
|
| 66 |
+
tts = gTTS(text=narration, lang='en')
|
| 67 |
+
audio_buffer = BytesIO()
|
| 68 |
+
tts.write_to_fp(audio_buffer)
|
| 69 |
+
audio_buffer.seek(0)
|
| 70 |
+
|
| 71 |
+
st.audio(audio_buffer, format='audio/mp3', start_time=0)
|
| 72 |
else:
|
| 73 |
st.write(st.session_state['history'][-1]['content'] if st.session_state['history'] else "Narration will appear here.")
|