Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1135,7 +1135,7 @@ class VideoGeneratorUI:
|
|
| 1135 |
st.rerun()
|
| 1136 |
|
| 1137 |
def show_image_selection(self):
|
| 1138 |
-
st.subheader("
|
| 1139 |
|
| 1140 |
# Display back button
|
| 1141 |
if st.button("← Back to Script"):
|
|
@@ -1154,20 +1154,21 @@ class VideoGeneratorUI:
|
|
| 1154 |
col1, col2 = st.columns([3, 1])
|
| 1155 |
|
| 1156 |
with col1:
|
| 1157 |
-
|
| 1158 |
-
selected_count = 0
|
| 1159 |
-
st.session_state.selected_images = [] # Reset selected images
|
| 1160 |
|
| 1161 |
for category, images in image_categories.items():
|
| 1162 |
if images:
|
| 1163 |
st.subheader(f"{category.title()} Images")
|
| 1164 |
selected = self.display_image_grid(images)
|
| 1165 |
-
|
| 1166 |
-
|
|
|
|
|
|
|
| 1167 |
|
| 1168 |
with col2:
|
| 1169 |
# Show selection summary
|
| 1170 |
st.subheader("Selection Summary")
|
|
|
|
| 1171 |
st.write(f"Selected: {selected_count} images")
|
| 1172 |
|
| 1173 |
if selected_count > 0:
|
|
@@ -1183,12 +1184,16 @@ class VideoGeneratorUI:
|
|
| 1183 |
except Exception as e:
|
| 1184 |
st.error(f"An error occurred: {str(e)}")
|
| 1185 |
print(f"Error in image selection: {str(e)}")
|
| 1186 |
-
|
| 1187 |
-
|
| 1188 |
def display_image_grid(self, images: List[Dict[str, str]], cols: int = 3) -> List[str]:
|
| 1189 |
"""Display images in a grid and return selected image URLs"""
|
| 1190 |
selected_urls = []
|
| 1191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1192 |
n_images = len(images)
|
| 1193 |
n_rows = (n_images + cols - 1) // cols
|
| 1194 |
|
|
@@ -1204,18 +1209,27 @@ class VideoGeneratorUI:
|
|
| 1204 |
st.image(img['url'], use_container_width=True)
|
| 1205 |
|
| 1206 |
# Create unique key for each checkbox
|
| 1207 |
-
checkbox_key = f"img_select_{row}_{col}_{img['url']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1208 |
|
|
|
|
| 1209 |
if st.checkbox(
|
| 1210 |
-
f"Select (Confidence: {img.get('relevance_score', 0)*100:.1f}%)",
|
| 1211 |
-
key=checkbox_key
|
|
|
|
| 1212 |
):
|
| 1213 |
selected_urls.append(img['url'])
|
| 1214 |
|
| 1215 |
# Show image metadata
|
| 1216 |
st.markdown(
|
| 1217 |
f"""<div style='font-size: 0.8em;'>
|
| 1218 |
-
Keywords: {img
|
| 1219 |
Category: {img.get('category', 'General')}
|
| 1220 |
</div>""",
|
| 1221 |
unsafe_allow_html=True
|
|
@@ -1224,8 +1238,8 @@ class VideoGeneratorUI:
|
|
| 1224 |
st.error(f"Error displaying image: {str(e)}")
|
| 1225 |
|
| 1226 |
return selected_urls
|
| 1227 |
-
|
| 1228 |
|
|
|
|
| 1229 |
def show_video_generation(self):
|
| 1230 |
st.subheader("Video Generation Settings")
|
| 1231 |
|
|
|
|
| 1135 |
st.rerun()
|
| 1136 |
|
| 1137 |
def show_image_selection(self):
|
| 1138 |
+
st.subheader("AI-Selected Images for Your Video")
|
| 1139 |
|
| 1140 |
# Display back button
|
| 1141 |
if st.button("← Back to Script"):
|
|
|
|
| 1154 |
col1, col2 = st.columns([3, 1])
|
| 1155 |
|
| 1156 |
with col1:
|
| 1157 |
+
selected_images = []
|
|
|
|
|
|
|
| 1158 |
|
| 1159 |
for category, images in image_categories.items():
|
| 1160 |
if images:
|
| 1161 |
st.subheader(f"{category.title()} Images")
|
| 1162 |
selected = self.display_image_grid(images)
|
| 1163 |
+
selected_images.extend(selected)
|
| 1164 |
+
|
| 1165 |
+
# Update session state with selected images
|
| 1166 |
+
st.session_state.selected_images = selected_images
|
| 1167 |
|
| 1168 |
with col2:
|
| 1169 |
# Show selection summary
|
| 1170 |
st.subheader("Selection Summary")
|
| 1171 |
+
selected_count = len(st.session_state.selected_images)
|
| 1172 |
st.write(f"Selected: {selected_count} images")
|
| 1173 |
|
| 1174 |
if selected_count > 0:
|
|
|
|
| 1184 |
except Exception as e:
|
| 1185 |
st.error(f"An error occurred: {str(e)}")
|
| 1186 |
print(f"Error in image selection: {str(e)}")
|
| 1187 |
+
|
| 1188 |
+
|
| 1189 |
def display_image_grid(self, images: List[Dict[str, str]], cols: int = 3) -> List[str]:
|
| 1190 |
"""Display images in a grid and return selected image URLs"""
|
| 1191 |
selected_urls = []
|
| 1192 |
|
| 1193 |
+
# Initialize session state for image selection if not exists
|
| 1194 |
+
if 'image_selections' not in st.session_state:
|
| 1195 |
+
st.session_state.image_selections = {}
|
| 1196 |
+
|
| 1197 |
n_images = len(images)
|
| 1198 |
n_rows = (n_images + cols - 1) // cols
|
| 1199 |
|
|
|
|
| 1209 |
st.image(img['url'], use_container_width=True)
|
| 1210 |
|
| 1211 |
# Create unique key for each checkbox
|
| 1212 |
+
checkbox_key = f"img_select_{row}_{col}_{hash(img['url'])}"
|
| 1213 |
+
|
| 1214 |
+
# Pre-select images based on AI confidence score
|
| 1215 |
+
default_selected = img.get('relevance_score', 0) > 0.6
|
| 1216 |
+
|
| 1217 |
+
# Initialize checkbox state if not exists
|
| 1218 |
+
if checkbox_key not in st.session_state.image_selections:
|
| 1219 |
+
st.session_state.image_selections[checkbox_key] = default_selected
|
| 1220 |
|
| 1221 |
+
# Create checkbox with persistent state
|
| 1222 |
if st.checkbox(
|
| 1223 |
+
f"Select (AI Confidence: {img.get('relevance_score', 0)*100:.1f}%)",
|
| 1224 |
+
key=checkbox_key,
|
| 1225 |
+
value=st.session_state.image_selections[checkbox_key]
|
| 1226 |
):
|
| 1227 |
selected_urls.append(img['url'])
|
| 1228 |
|
| 1229 |
# Show image metadata
|
| 1230 |
st.markdown(
|
| 1231 |
f"""<div style='font-size: 0.8em;'>
|
| 1232 |
+
Keywords: {img.get('keyword', 'N/A')}<br>
|
| 1233 |
Category: {img.get('category', 'General')}
|
| 1234 |
</div>""",
|
| 1235 |
unsafe_allow_html=True
|
|
|
|
| 1238 |
st.error(f"Error displaying image: {str(e)}")
|
| 1239 |
|
| 1240 |
return selected_urls
|
|
|
|
| 1241 |
|
| 1242 |
+
|
| 1243 |
def show_video_generation(self):
|
| 1244 |
st.subheader("Video Generation Settings")
|
| 1245 |
|