Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import convention
|
2 |
+
>>> import streamlit as st
|
3 |
+
from transformers import pipeline
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Load the image-to-text pipeline
|
7 |
+
image_read = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
8 |
+
|
9 |
+
def read(image):
|
10 |
+
results = image_read(image)
|
11 |
+
return results
|
12 |
+
|
13 |
+
# Streamlit UI
|
14 |
+
st.title("Storytelling from images for 3-10 year-old kids")
|
15 |
+
|
16 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
|
17 |
+
|
18 |
+
if uploaded_file is not None:
|
19 |
+
image = Image.open(uploaded_file).convert("RGB")
|
20 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
21 |
+
|
22 |
+
# Read image
|
23 |
+
image_content = read(image)
|
24 |
+
|
25 |
+
# Display results
|
26 |
+
st.subheader("Image Content:")
|
27 |
+
st.write(f"Image Content: {image_content[0]}")
|