File size: 1,313 Bytes
d78fda0
621bb5d
d78fda0
 
48bd4ea
 
 
106eff3
48bd4ea
 
621bb5d
 
 
 
 
d78fda0
48bd4ea
d78fda0
48bd4ea
 
 
ae103bc
 
48bd4ea
 
 
 
ae103bc
48bd4ea
 
 
24e5396
48bd4ea
 
a3766e8
ae103bc
24e5396
fb9ccfe
ae103bc
48bd4ea
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
40
41
42
43
44
45
46
import streamlit as st
from transformers import pipeline
from PIL import Image

# Page config
st.set_page_config(page_title="TinyLLaVA Snapshot", layout="centered")
st.title("πŸ“Έ TinyLLaVA β€” Snapshot Q&A (Hugging Face Spaces Safe)")

# Load TinyLLaVA pipeline
st.info("Loading TinyLLaVA... Please wait ⏳")
pipe = pipeline(
    task="image-to-text",
    model="bczhou/tiny-llava-v1-hf",
    trust_remote_code=True,
    device_map="cpu"
)
st.success("βœ… Model loaded!")

# Widgets
st.markdown("**1️⃣ Take a snapshot OR upload an image**")
image = st.camera_input("πŸ“· Click 'Take Photo' below:")

if not image:
    image = st.file_uploader("πŸ“‚ Or upload an image file", type=["jpg", "png", "jpeg"])

st.markdown("**2️⃣ Enter your question:**")
prompt = st.text_input("πŸ’¬", value="Describe this scene.")

# Debug info
st.write(f"πŸ“Έ Image uploaded: {'Yes' if image else 'No'}")
st.write(f"πŸ’¬ Prompt: {prompt}")

# If both present
if image and prompt:
    img = Image.open(image).convert("RGB")
    st.image(img, caption="Your Image", use_column_width=True)

    query = f"USER: <image>\n{prompt}\nASSISTANT:"

    with st.spinner("TinyLLaVA is generating..."):
        result = pipe(query, img)
        answer = result[0]["generated_text"]

    st.subheader("πŸ“ Answer")
    st.write(answer)