vishalkatheriya commited on
Commit
12ab3b2
·
verified ·
1 Parent(s): 9bc25a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -31
app.py CHANGED
@@ -8,12 +8,6 @@ st.markdown("""
8
  background-color: #f7f9fc;
9
  font-family: 'Arial', sans-serif;
10
  }
11
- .main {
12
- background-color: #ffffff;
13
- padding: 30px;
14
- border-radius: 15px;
15
- box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.1);
16
- }
17
  .title {
18
  color: #2c3e50;
19
  font-size: 40px;
@@ -68,49 +62,30 @@ if 'has_run' not in st.session_state:
68
  st.session_state.has_run = False
69
 
70
  # Main UI container
71
- st.markdown('<div class="main">', unsafe_allow_html=True)
72
  st.markdown('<div class="title">Florence-2 Image Captioning Demo</div>', unsafe_allow_html=True)
73
 
74
- # Task prompt input
75
- task_prompt = st.text_input("Task Prompt", value="Describe the image in detail:")
76
 
77
  # Image upload area
78
  st.sidebar.markdown('<div class="upload-area">', unsafe_allow_html=True)
79
  uploaded_image = st.sidebar.file_uploader("Upload your image here", type=["jpg", "jpeg", "png"])
80
  st.sidebar.markdown('</div>', unsafe_allow_html=True)
81
 
82
- # Additional text input (optional)
83
- text_input = st.text_area("Additional Text Input (Optional)", height=150)
84
 
85
  # Display the uploaded image and process it if available
86
  if uploaded_image is not None:
 
 
 
 
87
  image = Image.open(uploaded_image)
88
  st.image(image, caption="Uploaded Image", use_column_width=True)
89
 
90
  # Generate Caption button
91
- if st.button("Generate Caption", key="generate") and not st.session_state.has_run:
92
  # Mark that the script has been run
93
  st.session_state.has_run = True
94
 
95
- # Assuming `run_example` function is defined
96
- result = run_example(task_prompt, image, text_input)
97
-
98
- # Display the generated caption
99
- st.markdown('<div class="result-section">', unsafe_allow_html=True)
100
- st.markdown('<div class="result-title">Generated Caption</div>', unsafe_allow_html=True)
101
- st.markdown(f'<div class="success">{result["text"]}</div>', unsafe_allow_html=True)
102
-
103
- # Display bounding boxes or polygons if available
104
- if "bboxes" in result:
105
- st.markdown("### Detected Objects")
106
- fig = plot_bbox(image, result)
107
- st.pyplot(fig)
108
-
109
- if "polygons" in result:
110
- st.markdown("### Image with Polygons")
111
- processed_image = draw_polygons(image.copy(), result)
112
- st.image(processed_image, caption="Image with Polygons", use_column_width=True)
113
-
114
  # Clear session state button
115
  if st.session_state.has_run:
116
  if st.button("Clear and Upload New Image"):
 
8
  background-color: #f7f9fc;
9
  font-family: 'Arial', sans-serif;
10
  }
 
 
 
 
 
 
11
  .title {
12
  color: #2c3e50;
13
  font-size: 40px;
 
62
  st.session_state.has_run = False
63
 
64
  # Main UI container
 
65
  st.markdown('<div class="title">Florence-2 Image Captioning Demo</div>', unsafe_allow_html=True)
66
 
67
+
 
68
 
69
  # Image upload area
70
  st.sidebar.markdown('<div class="upload-area">', unsafe_allow_html=True)
71
  uploaded_image = st.sidebar.file_uploader("Upload your image here", type=["jpg", "jpeg", "png"])
72
  st.sidebar.markdown('</div>', unsafe_allow_html=True)
73
 
 
 
74
 
75
  # Display the uploaded image and process it if available
76
  if uploaded_image is not None:
77
+ # Task prompt input
78
+ task_prompt = st.text_input("Task Prompt", value="Describe the image in detail:")
79
+ # Additional text input (optional)
80
+ text_input = st.text_area("Additional Text Input (Optional)", height=150)
81
  image = Image.open(uploaded_image)
82
  st.image(image, caption="Uploaded Image", use_column_width=True)
83
 
84
  # Generate Caption button
85
+ if st.button("Generate Caption", key="Generate") and not st.session_state.has_run:
86
  # Mark that the script has been run
87
  st.session_state.has_run = True
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  # Clear session state button
90
  if st.session_state.has_run:
91
  if st.button("Clear and Upload New Image"):