Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1107,8 +1107,6 @@ class VideoGeneratorUI:
|
|
| 1107 |
st.set_page_config(layout="wide")
|
| 1108 |
|
| 1109 |
# Initialize session state
|
| 1110 |
-
if 'selected_images' not in st.session_state:
|
| 1111 |
-
st.session_state.selected_images = []
|
| 1112 |
if 'processing_complete' not in st.session_state:
|
| 1113 |
st.session_state.processing_complete = False
|
| 1114 |
if 'current_step' not in st.session_state:
|
|
@@ -1128,8 +1126,6 @@ class VideoGeneratorUI:
|
|
| 1128 |
with st.container():
|
| 1129 |
if st.session_state.current_step == 'input':
|
| 1130 |
self.show_input_form()
|
| 1131 |
-
elif st.session_state.current_step == 'image_selection':
|
| 1132 |
-
self.show_image_selection()
|
| 1133 |
elif st.session_state.current_step == 'video_generation':
|
| 1134 |
self.show_video_generation()
|
| 1135 |
|
|
@@ -1148,13 +1144,52 @@ class VideoGeneratorUI:
|
|
| 1148 |
["Professional Male", "Professional Female", "Casual Male", "Casual Female"]
|
| 1149 |
)
|
| 1150 |
|
| 1151 |
-
submit_button = st.form_submit_button(label='
|
| 1152 |
|
| 1153 |
if submit_button and prompt:
|
| 1154 |
st.session_state.prompt = prompt
|
| 1155 |
-
|
|
|
|
|
|
|
|
|
|
| 1156 |
st.rerun()
|
| 1157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1158 |
def show_image_selection(self):
|
| 1159 |
st.subheader("AI-Selected Images for Your Video")
|
| 1160 |
|
|
|
|
| 1107 |
st.set_page_config(layout="wide")
|
| 1108 |
|
| 1109 |
# Initialize session state
|
|
|
|
|
|
|
| 1110 |
if 'processing_complete' not in st.session_state:
|
| 1111 |
st.session_state.processing_complete = False
|
| 1112 |
if 'current_step' not in st.session_state:
|
|
|
|
| 1126 |
with st.container():
|
| 1127 |
if st.session_state.current_step == 'input':
|
| 1128 |
self.show_input_form()
|
|
|
|
|
|
|
| 1129 |
elif st.session_state.current_step == 'video_generation':
|
| 1130 |
self.show_video_generation()
|
| 1131 |
|
|
|
|
| 1144 |
["Professional Male", "Professional Female", "Casual Male", "Casual Female"]
|
| 1145 |
)
|
| 1146 |
|
| 1147 |
+
submit_button = st.form_submit_button(label='Generate Video')
|
| 1148 |
|
| 1149 |
if submit_button and prompt:
|
| 1150 |
st.session_state.prompt = prompt
|
| 1151 |
+
# Automatically select images based on AI analysis
|
| 1152 |
+
with st.spinner("AI analyzing script and selecting relevant images..."):
|
| 1153 |
+
self.auto_select_images()
|
| 1154 |
+
st.session_state.current_step = 'video_generation'
|
| 1155 |
st.rerun()
|
| 1156 |
|
| 1157 |
+
def auto_select_images(self):
|
| 1158 |
+
"""Automatically select the most relevant images based on AI analysis"""
|
| 1159 |
+
try:
|
| 1160 |
+
keywords = self.generator.image_scraper.extract_key_topics(st.session_state.prompt)
|
| 1161 |
+
st.write("🤖 AI-detected keywords:", ", ".join(keywords))
|
| 1162 |
+
|
| 1163 |
+
image_categories = self.generator.image_scraper.get_images(st.session_state.prompt)
|
| 1164 |
+
selected_images = []
|
| 1165 |
+
|
| 1166 |
+
if image_categories and isinstance(image_categories, dict):
|
| 1167 |
+
# Select top images from each category based on relevance score
|
| 1168 |
+
for category, images in image_categories.items():
|
| 1169 |
+
# Sort images by relevance score
|
| 1170 |
+
sorted_images = sorted(images, key=lambda x: x.get('relevance_score', 0), reverse=True)
|
| 1171 |
+
|
| 1172 |
+
# Select top images from each category
|
| 1173 |
+
num_to_select = {
|
| 1174 |
+
'primary': 3,
|
| 1175 |
+
'secondary': 2,
|
| 1176 |
+
'general': 1
|
| 1177 |
+
}.get(category.lower(), 1)
|
| 1178 |
+
|
| 1179 |
+
selected = [img['url'] for img in sorted_images[:num_to_select]]
|
| 1180 |
+
selected_images.extend(selected)
|
| 1181 |
+
|
| 1182 |
+
if not selected_images:
|
| 1183 |
+
# Fallback to stock images if no images were selected
|
| 1184 |
+
selected_images = self.generator.image_scraper.get_stock_images()[:6]
|
| 1185 |
+
|
| 1186 |
+
st.session_state.selected_images = selected_images
|
| 1187 |
+
|
| 1188 |
+
except Exception as e:
|
| 1189 |
+
st.error(f"Error in image selection: {str(e)}")
|
| 1190 |
+
# Fallback to stock images
|
| 1191 |
+
st.session_state.selected_images = self.generator.image_scraper.get_stock_images()[:6]
|
| 1192 |
+
|
| 1193 |
def show_image_selection(self):
|
| 1194 |
st.subheader("AI-Selected Images for Your Video")
|
| 1195 |
|