VLM / app.py
WaysAheadGlobal's picture
Update app.py
fb9ccfe verified
raw
history blame
1.13 kB
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)