File size: 1,180 Bytes
8533608
9322a5c
8987036
9322a5c
8533608
9a60ca7
 
 
 
 
 
8533608
c3c7832
8533608
c3c7832
 
8533608
 
9a60ca7
c3c7832
 
 
9a60ca7
 
 
 
 
 
 
c3c7832
 
9a60ca7
 
c3c7832
 
 
 
9a60ca7
 
149b30a
 
 
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
# import part
import streamlit as st
from transformers import pipeline

# function part
# 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




def main():
    # App title
    st.title("Streamlit Demo on Hugging Face")

    # Write some text
    st.write("Welcome to a demo app showcasing basic Streamlit components!")
    
    uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])

    if uploaded_file is not None:

        st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)


        #Stage 1: Image to Text
        st.text('Processing img2text...')
        image_caption = generate_image_caption(uploaded_image.name)
        st.write(image_caption)

if __name__ == "__main__":
    main()