Spaces:
Sleeping
Sleeping
File size: 2,953 Bytes
1ce5af6 9f6c987 1ce5af6 b18b389 1ce5af6 44587a3 1ce5af6 e9ccf83 1ce5af6 9f6c987 1ce5af6 ace8632 c8bb585 ace8632 1ce5af6 c8bb585 ace8632 c8bb585 ace8632 b18b389 1ce5af6 ace8632 b18b389 c8bb585 ace8632 3a742c5 ace8632 3a742c5 ace8632 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
import os
import streamlit as st
from PIL import Image
import os
from models.imageCaptioning import generateCaption
from models.storyGeneration import generateStory
st.set_page_config(page_title="Image2Story Generator", layout="centered")
st.title("Image2Story Generator")
st.write("Upload your Image and let us generate a Story for you")
upload_dir = "/tmp/uploads"
os.makedirs(upload_dir, exist_ok=True)
#Upload your file
uploaded_file = st.sidebar.file_uploader("Upload Your Image", type= ["jpg" , "jpeg" , "png" , "webp"])
if uploaded_file:
image = Image.open(uploaded_file).convert("RGB")
image_path = os.path.join(upload_dir, uploaded_file.name)
image.save(image_path)
# st.image(image, caption="uploaded image" , use_container_width=True)
# with st.spinner("Generating Captions..."):
# caption = generateCaption(image_path)
# st.success(f"The image is of : {caption}")
with st.spinner("Generating Captions..."):
caption = generateCaption(image_path)
st.success("Caption generated successfully!")
st.markdown(f"""
<div style="background-color:#f0f2f6;padding:15px 20px;border-radius:10px;margin-top:20px;border-left:5px solid #4CAF50;">
<h4 style="margin-bottom:10px;">๐ผ๏ธ <strong>Scenario is :</strong></h4>
<p style="font-size:16px;color:#333;">{caption}</p>
</div>
""", unsafe_allow_html=True)
story_style = st.sidebar.selectbox("Choose Story Style" , ["William Shakespeare" , "Leo Tolstoy", "Charles Dickens" , "Haruki Murakami" , "J.K. Rowling" , "Stephen King"])
prompt = f"""
You are a professional story writer with a deep understanding of surreal and introspective storytelling, inspired by {story_style}.
Write a short story based on the theme: {caption.strip()}.
The story should be in between 500 and 800 words, and must include:
- A clear beginning and ending.
- Subtle emotional depth and a dreamlike atmosphere.
- Elements typical of {story_style}'s writing style.
Do not include a title. Return only the story.
"""
# with st.spinner("Generating Story..."):
# story = generateStory(captions)
# st.markdown("Generated Story")
# st.write(story)
with st.spinner("Generating Story..."):
story = generateStory(caption)
st.markdown("""
<div style="background-color:#f9f9f9;padding:15px 20px;border-radius:10px;margin-top:20px;border-left:5px solid #2196F3;">
<h4 style="margin-bottom:10px;">๐ <strong>Generated Story</strong></h4>
""", unsafe_allow_html=True)
formatted_story = story.replace('\n', '<br>')
st.markdown(f"""
<div style="font-size:16px;line-height:1.6;color:#444;">
{formatted_story}
</div>
</div>
""", unsafe_allow_html=True) |