File size: 931 Bytes
d78fda0
 
 
621bb5d
d78fda0
621bb5d
d78fda0
621bb5d
 
d78fda0
621bb5d
 
 
 
 
d78fda0
 
621bb5d
 
d78fda0
621bb5d
d78fda0
621bb5d
d78fda0
621bb5d
d78fda0
621bb5d
 
d78fda0
9aa78bc
621bb5d
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
# app.py

import streamlit as st
from transformers import pipeline
from PIL import Image
import requests

st.set_page_config(page_title="TinyLLaVA (Streamlit)", layout="centered")
st.title("πŸ¦™ TinyLLaVA β€” Vision-Language Q&A")

pipe = pipeline(
    task="image-to-text",
    model="bczhou/tiny-llava-v1-hf",
    trust_remote_code=True,
    device_map="cpu"
)

uploaded_file = st.file_uploader("πŸ“· Upload an image", type=["jpg","png","jpeg"])
prompt = st.text_input("πŸ’¬ Ask a question (post `<image>` token):", value="What is happening?")

if uploaded_file and prompt:
    image = Image.open(uploaded_file).convert("RGB")
    st.image(image, caption="Uploaded Image", use_column_width=True)

    query = f"USER: <image>\n{prompt}\nASSISTANT:"
    with st.spinner("Generating answer..."):
        result = pipe(query, image)
        answer = result[0]["generated_text"]

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