Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,39 +2,42 @@ 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
|
| 7 |
-
st.title("πΈ TinyLLaVA β Snapshot Q&A (Spaces Safe)")
|
| 8 |
|
| 9 |
-
# Load
|
|
|
|
| 10 |
pipe = pipeline(
|
| 11 |
task="image-to-text",
|
| 12 |
model="bczhou/tiny-llava-v1-hf",
|
| 13 |
trust_remote_code=True,
|
| 14 |
device_map="cpu"
|
| 15 |
)
|
|
|
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
st.markdown("
|
|
|
|
| 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 |
-
#
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
if image
|
| 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("
|
| 38 |
result = pipe(query, img)
|
| 39 |
answer = result[0]["generated_text"]
|
| 40 |
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
+
# Page config
|
| 6 |
+
st.set_page_config(page_title="TinyLLaVA Snapshot", layout="centered")
|
| 7 |
+
st.title("πΈ TinyLLaVA β Snapshot Q&A (Hugging Face Spaces Safe)")
|
| 8 |
|
| 9 |
+
# Load TinyLLaVA pipeline
|
| 10 |
+
st.info("Loading TinyLLaVA... Please wait β³")
|
| 11 |
pipe = pipeline(
|
| 12 |
task="image-to-text",
|
| 13 |
model="bczhou/tiny-llava-v1-hf",
|
| 14 |
trust_remote_code=True,
|
| 15 |
device_map="cpu"
|
| 16 |
)
|
| 17 |
+
st.success("β
Model loaded!")
|
| 18 |
|
| 19 |
+
# Widgets
|
| 20 |
+
st.markdown("**1οΈβ£ Take a snapshot OR upload an image**")
|
| 21 |
+
image = st.camera_input("π· Click 'Take Photo' below:")
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
if not image:
|
| 24 |
+
image = st.file_uploader("π Or upload an image file", type=["jpg", "png", "jpeg"])
|
| 25 |
+
|
| 26 |
+
st.markdown("**2οΈβ£ Enter your question:**")
|
| 27 |
+
prompt = st.text_input("π¬", value="Describe this scene.")
|
| 28 |
|
| 29 |
+
# Debug info
|
| 30 |
+
st.write(f"πΈ Image uploaded: {'Yes' if image else 'No'}")
|
| 31 |
+
st.write(f"π¬ Prompt: {prompt}")
|
| 32 |
|
| 33 |
+
# If both present
|
| 34 |
+
if image and prompt:
|
| 35 |
img = Image.open(image).convert("RGB")
|
| 36 |
st.image(img, caption="Your Image", use_column_width=True)
|
| 37 |
|
| 38 |
query = f"USER: <image>\n{prompt}\nASSISTANT:"
|
| 39 |
|
| 40 |
+
with st.spinner("TinyLLaVA is generating..."):
|
| 41 |
result = pipe(query, img)
|
| 42 |
answer = result[0]["generated_text"]
|
| 43 |
|