VLM / app.py
WaysAheadGlobal's picture
Update app.py
621bb5d verified
raw
history blame
931 Bytes
# 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)