vishalkatheriya commited on
Commit
9bc25a6
1 Parent(s): 887ecc1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -63,6 +63,10 @@ st.markdown("""
63
  </style>
64
  """, unsafe_allow_html=True)
65
 
 
 
 
 
66
  # Main UI container
67
  st.markdown('<div class="main">', unsafe_allow_html=True)
68
  st.markdown('<div class="title">Florence-2 Image Captioning Demo</div>', unsafe_allow_html=True)
@@ -71,9 +75,9 @@ st.markdown('<div class="title">Florence-2 Image Captioning Demo</div>', unsafe_
71
  task_prompt = st.text_input("Task Prompt", value="Describe the image in detail:")
72
 
73
  # Image upload area
74
- st.markdown('<div class="upload-area">', unsafe_allow_html=True)
75
- uploaded_image = st.file_uploader("Upload your image here", type=["jpg", "jpeg", "png"])
76
- st.markdown('</div>', unsafe_allow_html=True)
77
 
78
  # Additional text input (optional)
79
  text_input = st.text_area("Additional Text Input (Optional)", height=150)
@@ -84,7 +88,10 @@ if uploaded_image is not None:
84
  st.image(image, caption="Uploaded Image", use_column_width=True)
85
 
86
  # Generate Caption button
87
- if st.button("Generate Caption", key="generate"):
 
 
 
88
  # Assuming `run_example` function is defined
89
  result = run_example(task_prompt, image, text_input)
90
 
@@ -104,4 +111,10 @@ if uploaded_image is not None:
104
  processed_image = draw_polygons(image.copy(), result)
105
  st.image(processed_image, caption="Image with Polygons", use_column_width=True)
106
 
 
 
 
 
 
 
107
  st.markdown('</div>', unsafe_allow_html=True)
 
63
  </style>
64
  """, unsafe_allow_html=True)
65
 
66
+ # Initialize session state to block re-running
67
+ 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)
 
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)
 
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
 
 
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"):
117
+ st.session_state.has_run = False
118
+ st.experimental_rerun()
119
+
120
  st.markdown('</div>', unsafe_allow_html=True)