Spaces:
Sleeping
Sleeping
| # 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) | |