Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import pipeline | |
| from PIL import Image | |
| # Configure the Streamlit page | |
| st.set_page_config(page_title="TinyLLaVA Snapshot", layout="centered") | |
| st.title("π· TinyLLaVA β Snapshot Webcam (Spaces Compatible)") | |
| # Load TinyLLaVA pipeline once | |
| pipe = pipeline( | |
| task="image-to-text", | |
| model="bczhou/tiny-llava-v1-hf", | |
| trust_remote_code=True, | |
| device_map="cpu" | |
| ) | |
| # Camera input | |
| uploaded_image = st.camera_input("πΈ Take a photo") | |
| # Prompt input | |
| prompt = st.text_input("π¬ Your question about the image:", value="Describe this scene in detail.") | |
| # Process when both image and prompt are present | |
| if uploaded_image and prompt: | |
| # Convert to PIL image | |
| img = Image.open(uploaded_image).convert("RGB") | |
| # Build prompt in TinyLLaVA format | |
| query = f"USER: <image>\n{prompt}\nASSISTANT:" | |
| with st.spinner("TinyLLaVA is thinking..."): | |
| result = pipe(query, img) | |
| answer = result[0]["generated_text"] | |
| # Show uploaded image + answer | |
| st.image(img, caption="Your Snapshot", use_column_width=True) | |
| st.subheader("π Answer") | |
| st.write(answer) | |