File size: 1,134 Bytes
d78fda0
621bb5d
d78fda0
 
fb9ccfe
 
 
106eff3
fb9ccfe
621bb5d
 
 
 
 
d78fda0
 
fb9ccfe
 
24e5396
fb9ccfe
 
24e5396
fb9ccfe
 
 
 
24e5396
fb9ccfe
 
d78fda0
fb9ccfe
 
 
d78fda0
fb9ccfe
 
 
 
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
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)