Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,11 +2,11 @@ import streamlit as st
|
|
| 2 |
from transformers import pipeline
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
-
#
|
| 6 |
st.set_page_config(page_title="TinyLLaVA Snapshot Q&A", layout="centered")
|
| 7 |
-
st.title("πΈ TinyLLaVA
|
| 8 |
|
| 9 |
-
# Load
|
| 10 |
pipe = pipeline(
|
| 11 |
task="image-to-text",
|
| 12 |
model="bczhou/tiny-llava-v1-hf",
|
|
@@ -14,19 +14,27 @@ pipe = pipeline(
|
|
| 14 |
device_map="cpu"
|
| 15 |
)
|
| 16 |
|
| 17 |
-
#
|
|
|
|
|
|
|
|
|
|
| 18 |
image = st.camera_input("π· Take a snapshot")
|
| 19 |
|
| 20 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
prompt = st.text_input("π¬ Your question:", value="Describe this scene.")
|
| 22 |
|
| 23 |
-
#
|
| 24 |
if image is not None and prompt:
|
| 25 |
img = Image.open(image).convert("RGB")
|
| 26 |
-
st.image(img, caption="Your
|
| 27 |
|
| 28 |
query = f"USER: <image>\n{prompt}\nASSISTANT:"
|
| 29 |
-
|
|
|
|
| 30 |
result = pipe(query, img)
|
| 31 |
answer = result[0]["generated_text"]
|
| 32 |
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
+
# Setup
|
| 6 |
st.set_page_config(page_title="TinyLLaVA Snapshot Q&A", layout="centered")
|
| 7 |
+
st.title("πΈ TinyLLaVA β Snapshot Q&A (Spaces Safe)")
|
| 8 |
|
| 9 |
+
# Load model
|
| 10 |
pipe = pipeline(
|
| 11 |
task="image-to-text",
|
| 12 |
model="bczhou/tiny-llava-v1-hf",
|
|
|
|
| 14 |
device_map="cpu"
|
| 15 |
)
|
| 16 |
|
| 17 |
+
# π Clear info so the widget tree is stable
|
| 18 |
+
st.markdown("Use your **webcam** OR upload a file:")
|
| 19 |
+
|
| 20 |
+
# Try webcam first
|
| 21 |
image = st.camera_input("π· Take a snapshot")
|
| 22 |
|
| 23 |
+
# Fallback uploader
|
| 24 |
+
if not image:
|
| 25 |
+
image = st.file_uploader("π Or upload an image", type=["jpg", "png", "jpeg"])
|
| 26 |
+
|
| 27 |
+
# Prompt
|
| 28 |
prompt = st.text_input("π¬ Your question:", value="Describe this scene.")
|
| 29 |
|
| 30 |
+
# Run TinyLLaVA
|
| 31 |
if image is not None and prompt:
|
| 32 |
img = Image.open(image).convert("RGB")
|
| 33 |
+
st.image(img, caption="Your Image", use_column_width=True)
|
| 34 |
|
| 35 |
query = f"USER: <image>\n{prompt}\nASSISTANT:"
|
| 36 |
+
|
| 37 |
+
with st.spinner("Generating..."):
|
| 38 |
result = pipe(query, img)
|
| 39 |
answer = result[0]["generated_text"]
|
| 40 |
|