Spaces:
Sleeping
Sleeping
File size: 1,148 Bytes
8533608 9322a5c 8533608 f4f24b0 8533608 f4f24b0 8533608 f4f24b0 8533608 f4f24b0 8533608 859797f 8533608 f4f24b0 |
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 |
# import part
import streamlit as st
from PIL import Image
import time
# function part
def generate_image_caption(image_path):
"""Generates a caption for the given image using a pre-trained model."""
img2caption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
result = img2caption(image_path)
return result[0]['generated_text']
# text2story
def text2story(text):
pipe = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
story_text = pipe(text)[0]['generated_text']
return story_text
# main part
# App title
st.title("Assignment")
# Write some text
st.write("Image to Story")
# File uploader for image and audio
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
# Display image with spinner
if uploaded_image is not None:
with st.spinner("Loading image..."):
time.sleep(1) # Simulate a delay
image = Image.open(uploaded_image)
st.image(image, caption="Uploaded Image", use_column_width=True)
caption = generate_image_caption(uploaded_image)
st.write("Generated Caption: {caption}")
|