Spaces:
Sleeping
Sleeping
File size: 1,593 Bytes
25b1f34 8999ad7 1c6aece e223dbc 8999ad7 1c6aece e223dbc 9170c17 8999ad7 9170c17 8999ad7 9170c17 8999ad7 9170c17 8999ad7 9170c17 e223dbc 9170c17 60d2cac 9170c17 f7f1988 60d2cac f7f1988 e223dbc f7f1988 |
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 |
import streamlit as st
from transformers import pipeline
from PIL import Image
@st.cache_resource
def get_model_hotdog_classification():
model = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
return model
@st.cache_resource
def get_model_image_captioning():
captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
return captioner
tabs1,tabs2 = st.tabs(['Hot Dog? Or Not?','Imaage Captioning'])
with tabs1:
st.title("Hot Dog? Or Not?")
file_name = st.file_uploader("Upload a hot dog candidate image",key="hotdog_image")
if file_name is not None:
col1, col2 = st.columns(2)
image = Image.open(file_name)
col1.image(image, use_column_width=True)
model = get_model_hotdog_classification()
predictions = model(image)
col2.header("Probabilities")
for p in predictions:
col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
with tabs2:
st.title("Image Captioning")
file_name = st.file_uploader("Upload an image to caption",key="caption_image")
if file_name is not None:
col1, col2 = st.columns(2)
image = Image.open(file_name)
col1.image(image, use_column_width=True)
captioner = get_model_image_captioning()
with col2:
st.header("generated caption")
with st.spinner("Generating caption..."):
predictions = captioner(image)
for generated_text in predictions:
st.write(f"\n{generated_text['generated_text']}") |