vishalkatheriya
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
|
4 |
+
# UI Layout
|
5 |
+
st.title("Florence-2 Demo")
|
6 |
+
|
7 |
+
# Sidebar for model selection
|
8 |
+
model_option = st.sidebar.selectbox(
|
9 |
+
"Select Model",
|
10 |
+
("microsoft/Florence-2-large-ft", "microsoft/Florence-2-large", "microsoft/Florence-2-base-ft", "microsoft/Florence-2-base")
|
11 |
+
)
|
12 |
+
|
13 |
+
# Task prompt selection
|
14 |
+
task_prompt = st.text_input("Task Prompt", value="Caption the image:")
|
15 |
+
|
16 |
+
# Text input (optional)
|
17 |
+
text_input = st.text_input("Text Input (Optional)")
|
18 |
+
|
19 |
+
# Image upload
|
20 |
+
uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
|
21 |
+
|
22 |
+
# Process the image if one is uploaded
|
23 |
+
if uploaded_image is not None:
|
24 |
+
image = Image.open(uploaded_image)
|
25 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
26 |
+
|
27 |
+
# Run the model
|
28 |
+
if st.button("Run"):
|
29 |
+
# Assuming `run_example` function and others are defined as per the previous code snippet.
|
30 |
+
result = run_example(task_prompt, image, text_input, model_option)
|
31 |
+
|
32 |
+
# Display results
|
33 |
+
st.subheader("Generated Output")
|
34 |
+
st.write(result["text"]) # Display the generated text
|
35 |
+
|
36 |
+
# Display bounding boxes if available
|
37 |
+
if "bboxes" in result:
|
38 |
+
fig = plot_bbox(image, result)
|
39 |
+
st.pyplot(fig)
|
40 |
+
|
41 |
+
# Display polygons if available
|
42 |
+
if "polygons" in result:
|
43 |
+
processed_image = draw_polygons(image.copy(), result)
|
44 |
+
st.image(processed_image, caption="Image with Polygons", use_column_width=True)
|