Update app.py
Browse files
app.py
CHANGED
|
@@ -23,20 +23,41 @@ def load_model():
|
|
| 23 |
processor, model = load_model()
|
| 24 |
|
| 25 |
# Streamlit UI
|
| 26 |
-
st.title("🖼️ Image
|
| 27 |
|
| 28 |
uploaded_file = st.file_uploader("Upload an Image", type=["png", "jpg", "jpeg"])
|
| 29 |
|
| 30 |
if uploaded_file:
|
| 31 |
image = Image.open(uploaded_file).convert("RGB")
|
| 32 |
-
st.image(image, caption="Uploaded Image",
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
processor, model = load_model()
|
| 24 |
|
| 25 |
# Streamlit UI
|
| 26 |
+
st.title("🖼️ Image Understanding with PaliGemma")
|
| 27 |
|
| 28 |
uploaded_file = st.file_uploader("Upload an Image", type=["png", "jpg", "jpeg"])
|
| 29 |
|
| 30 |
if uploaded_file:
|
| 31 |
image = Image.open(uploaded_file).convert("RGB")
|
| 32 |
+
st.image(image, caption="Uploaded Image", use_container_width=True)
|
| 33 |
+
|
| 34 |
+
# User selects the task
|
| 35 |
+
task = st.selectbox(
|
| 36 |
+
"Select a task:",
|
| 37 |
+
["Generate a caption", "Answer a question", "Detect objects", "Generate segmentation"]
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# User input for question/prompt
|
| 41 |
+
prompt = st.text_area("Enter a prompt (e.g., 'Describe the image' or 'What objects are present?')")
|
| 42 |
+
|
| 43 |
+
if st.button("Run"):
|
| 44 |
+
if prompt:
|
| 45 |
+
inputs = processor(text=prompt, images=image, return_tensors="pt")
|
| 46 |
+
|
| 47 |
+
with torch.no_grad():
|
| 48 |
+
output = model.generate(**inputs)
|
| 49 |
+
|
| 50 |
+
raw_output = processor.batch_decode(output, skip_special_tokens=False)[0]
|
| 51 |
+
|
| 52 |
+
# Handle different outputs
|
| 53 |
+
if task == "Generate a caption":
|
| 54 |
+
answer = raw_output
|
| 55 |
+
elif task == "Answer a question":
|
| 56 |
+
answer = raw_output
|
| 57 |
+
elif task == "Detect objects":
|
| 58 |
+
answer = f"Object bounding boxes: {raw_output}"
|
| 59 |
+
elif task == "Generate segmentation":
|
| 60 |
+
answer = f"Segmentation codes: {raw_output}"
|
| 61 |
+
|
| 62 |
+
st.success(f"✅ Result: {answer}")
|
| 63 |
+
|