Skip to content

Commit

Permalink
try catch global
Browse files Browse the repository at this point in the history
  • Loading branch information
manufy committed May 17, 2024
1 parent 8c55144 commit 8749451
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions 3-experiments/1-photo-story-teller/photostoryteller.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,41 +113,49 @@ def text2speech(message):


def main():
st.set_page_config(page_title="ManuAI Experiment 1 - Photo Story Teller", page_icon="📸", layout="wide")
st.header("ManuAI Experiment 1 - Photo Story Generation and Audio Teller")

st.write("Upload a photo and the application will generate a story based on the photo.")
st.write("The application uses the Hugging Face API to generate a scenario based on the photo, and then uses the OpenAI API to generate a story based on the scenario.")
st.write("The story is then converted usint a TTS model using the Hugging Face inference API to generate the audio.")
try:
st.set_page_config(page_title="ManuAI Experiment 1 - Photo Story Teller", page_icon="📸", layout="wide")
st.header("ManuAI Experiment 1 - Photo Story Generation and Audio Teller")

st.write("Still WIP, this deploy is for demo purposes only.")

uploaded_file = st.file_uploader("Choose a jpg base64 encoded photo...", type="jpg")
if uploaded_file is not None:
print("uploaded file")
bytes_data = uploaded_file.getvalue()
with open("photo.jpg", "wb") as f:
f.write(bytes_data)
st.image(uploaded_file, caption="Uploaded photo", use_column_width=True)

with st.spinner(text="Generating IMG2TEXT scenario..."):
scenario = img2text(uploaded_file.name)
st.success('Scenario generated!')

st.write("Upload a photo and the application will generate a story based on the photo.")
st.write("The application uses the Hugging Face API to generate a scenario based on the photo, and then uses the OpenAI API to generate a story based on the scenario.")
st.write("The story is then converted usint a TTS model using the Hugging Face inference API to generate the audio.")

st.write("Still WIP, this deploy is for demo purposes only.")




with st.spinner(text="Generating LLM story..."):
story = generate_story(scenario)
st.success('Story generated!')

with st.spinner(text="Generating Audio TTS output..."):
text2speech(story)
st.success('Audio generated!')

with st.expander("scenario"):
st.write(scenario)
with st.expander("story"):
st.write(story)
st.audio("audio.flac")
uploaded_file = st.file_uploader("Choose a jpg base64 encoded photo...", type="jpg")
if uploaded_file is not None:
print("uploaded file")
bytes_data = uploaded_file.getvalue()
with open("photo.jpg", "wb") as f:
f.write(bytes_data)
st.image(uploaded_file, caption="Uploaded photo", use_column_width=True)

with st.spinner(text="Generating IMG2TEXT scenario..."):
scenario = img2text(uploaded_file.name)
st.success('Scenario generated!')


with st.spinner(text="Generating LLM story..."):
story = generate_story(scenario)
st.success('Story generated!')

with st.spinner(text="Generating Audio TTS output..."):
text2speech(story)
st.success('Audio generated!')

with st.expander("scenario"):
st.write(scenario)
with st.expander("story"):
st.write(story)
st.audio("audio.flac")
except:
st.error('Some unexpected exception has occurred, remember', icon="🚨")

if __name__ == "__main__":
main()

0 comments on commit 8749451

Please sign in to comment.