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']}")