StorySeed / app.py
anasrz's picture
Update app.py
36649a6
import streamlit as st
from footer import footer
import pandas as pd
from io import StringIO
import os
from pathlib import Path
Path("./tempDir").mkdir(parents=True, exist_ok=True)
# Image
from PIL import Image
streamlit_style = """
<style>
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300&display=swap');
html, body, [class*="css"] {
font-family: 'Montserrat', sans-serif;
}
</style>
"""
st.markdown(streamlit_style, unsafe_allow_html=True)
#@st.cache
def load_image(image_file):
img = Image.open(image_file)
return img
col1, col2, col3 = st.columns(3)
with col1:
st.write(' ')
with col2:
st.image("./seed-1.png", width=200)
with col3:
st.write(' ')
footer()
st.markdown("<h1 style='text-align: center; '>StorySeed</h1>", unsafe_allow_html=True)
st.markdown("<p style='text-align: center; '>Plant the seed of your story with a picture.</p>", unsafe_allow_html=True)
image_file = st.file_uploader("Upload An Image",type=['png','jpeg','jpg'])
from model import get_story
if image_file is not None:
file_details = {"FileName":image_file.name,"FileType":image_file.type}
img = load_image(image_file)
st.image(img)
img_path = os.path.join("tempDir",image_file.name)
with open(img_path,"wb") as f:
f.write(image_file.getbuffer())
with st.spinner("File uploaded. Writing Story.."):
story = get_story(img_path)
st.success("Here's your story.. πŸŽ‰")
st.write(story)