Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
3 |
from gtts import gTTS
|
4 |
import io
|
|
|
5 |
|
6 |
# Load the image captioning model
|
7 |
caption_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
@@ -18,7 +19,7 @@ def generate_caption(image):
|
|
18 |
def generate_story(caption):
|
19 |
# Generate the story based on the caption
|
20 |
input_ids = tokenizer.encode(caption, return_tensors="pt")
|
21 |
-
output = text_generation_model.generate(input_ids, max_length=
|
22 |
story = tokenizer.decode(output[0], skip_special_tokens=True)
|
23 |
return story
|
24 |
|
@@ -33,15 +34,18 @@ def convert_to_audio(story):
|
|
33 |
def main():
|
34 |
st.title("Storytelling Application")
|
35 |
|
36 |
-
# File uploader for the image
|
37 |
-
uploaded_image = st.file_uploader("Upload an image", type=["jpg"
|
38 |
|
39 |
if uploaded_image is not None:
|
|
|
|
|
|
|
40 |
# Display the uploaded image
|
41 |
-
st.image(
|
42 |
|
43 |
# Generate the caption for the image
|
44 |
-
caption = generate_caption(
|
45 |
st.subheader("Generated Caption:")
|
46 |
st.write(caption)
|
47 |
|
|
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
3 |
from gtts import gTTS
|
4 |
import io
|
5 |
+
from PIL import Image
|
6 |
|
7 |
# Load the image captioning model
|
8 |
caption_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
|
|
19 |
def generate_story(caption):
|
20 |
# Generate the story based on the caption
|
21 |
input_ids = tokenizer.encode(caption, return_tensors="pt")
|
22 |
+
output = text_generation_model.generate(input_ids, max_length=100, num_return_sequences=1)
|
23 |
story = tokenizer.decode(output[0], skip_special_tokens=True)
|
24 |
return story
|
25 |
|
|
|
34 |
def main():
|
35 |
st.title("Storytelling Application")
|
36 |
|
37 |
+
# File uploader for the image (restricted to JPG)
|
38 |
+
uploaded_image = st.file_uploader("Upload an image", type=["jpg"])
|
39 |
|
40 |
if uploaded_image is not None:
|
41 |
+
# Convert the uploaded image to PIL image
|
42 |
+
image = Image.open(uploaded_image)
|
43 |
+
|
44 |
# Display the uploaded image
|
45 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
46 |
|
47 |
# Generate the caption for the image
|
48 |
+
caption = generate_caption(image)
|
49 |
st.subheader("Generated Caption:")
|
50 |
st.write(caption)
|
51 |
|