Update app.py
Browse files
app.py
CHANGED
@@ -125,7 +125,7 @@ def start_feed(tag, current_index, feed_items):
|
|
125 |
|
126 |
# Set loading state
|
127 |
is_loading = True
|
128 |
-
|
129 |
|
130 |
try:
|
131 |
ideas = generate_ideas(tag)
|
@@ -136,10 +136,31 @@ def start_feed(tag, current_index, feed_items):
|
|
136 |
print(f"Error in start_feed: {e}")
|
137 |
feed_items = []
|
138 |
current_index = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
# Set loading state to False and update UI
|
141 |
is_loading = False
|
142 |
-
|
|
|
143 |
|
144 |
def load_next(tag, current_index, feed_items):
|
145 |
"""
|
@@ -154,7 +175,7 @@ def load_next(tag, current_index, feed_items):
|
|
154 |
tuple: (current_tag, current_index, feed_items, html_content, is_loading)
|
155 |
"""
|
156 |
is_loading = True
|
157 |
-
|
158 |
|
159 |
try:
|
160 |
if current_index + 1 < len(feed_items):
|
@@ -166,10 +187,30 @@ def load_next(tag, current_index, feed_items):
|
|
166 |
current_index = len(feed_items) - 1
|
167 |
except Exception as e:
|
168 |
print(f"Error in load_next: {e}")
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
is_loading = False
|
172 |
-
|
|
|
173 |
|
174 |
def load_previous(tag, current_index, feed_items):
|
175 |
"""
|
@@ -185,7 +226,8 @@ def load_previous(tag, current_index, feed_items):
|
|
185 |
"""
|
186 |
if current_index > 0:
|
187 |
current_index -= 1
|
188 |
-
|
|
|
189 |
|
190 |
def generate_html(feed_items, scroll_to_latest=False, current_index=0, tag="", is_loading=False):
|
191 |
"""
|
|
|
125 |
|
126 |
# Set loading state
|
127 |
is_loading = True
|
128 |
+
html_content = generate_html([], False, 0, tag, is_loading)
|
129 |
|
130 |
try:
|
131 |
ideas = generate_ideas(tag)
|
|
|
136 |
print(f"Error in start_feed: {e}")
|
137 |
feed_items = []
|
138 |
current_index = 0
|
139 |
+
html_content = """
|
140 |
+
<div style="
|
141 |
+
display: flex;
|
142 |
+
flex-direction: column;
|
143 |
+
align-items: center;
|
144 |
+
justify-content: center;
|
145 |
+
max-width: 360px;
|
146 |
+
margin: 0 auto;
|
147 |
+
background-color: #000;
|
148 |
+
height: 640px;
|
149 |
+
border: 1px solid #333;
|
150 |
+
border-radius: 10px;
|
151 |
+
color: white;
|
152 |
+
font-family: Arial, sans-serif;
|
153 |
+
">
|
154 |
+
<p>Error generating content. Please try again!</p>
|
155 |
+
</div>
|
156 |
+
"""
|
157 |
+
is_loading = False
|
158 |
+
return tag, current_index, feed_items, html_content, is_loading
|
159 |
|
160 |
# Set loading state to False and update UI
|
161 |
is_loading = False
|
162 |
+
html_content = generate_html(feed_items, False, current_index, tag, is_loading)
|
163 |
+
return tag, current_index, feed_items, html_content, is_loading
|
164 |
|
165 |
def load_next(tag, current_index, feed_items):
|
166 |
"""
|
|
|
175 |
tuple: (current_tag, current_index, feed_items, html_content, is_loading)
|
176 |
"""
|
177 |
is_loading = True
|
178 |
+
html_content = generate_html(feed_items, False, current_index, tag, is_loading)
|
179 |
|
180 |
try:
|
181 |
if current_index + 1 < len(feed_items):
|
|
|
187 |
current_index = len(feed_items) - 1
|
188 |
except Exception as e:
|
189 |
print(f"Error in load_next: {e}")
|
190 |
+
html_content = """
|
191 |
+
<div style="
|
192 |
+
display: flex;
|
193 |
+
flex-direction: column;
|
194 |
+
align-items: center;
|
195 |
+
justify-content: center;
|
196 |
+
max-width: 360px;
|
197 |
+
margin: 0 auto;
|
198 |
+
background-color: #000;
|
199 |
+
height: 640px;
|
200 |
+
border: 1px solid #333;
|
201 |
+
border-radius: 10px;
|
202 |
+
color: white;
|
203 |
+
font-family: Arial, sans-serif;
|
204 |
+
">
|
205 |
+
<p>Error generating content. Please try again!</p>
|
206 |
+
</div>
|
207 |
+
"""
|
208 |
+
is_loading = False
|
209 |
+
return tag, current_index, feed_items, html_content, is_loading
|
210 |
|
211 |
is_loading = False
|
212 |
+
html_content = generate_html(feed_items, False, current_index, tag, is_loading)
|
213 |
+
return tag, current_index, feed_items, html_content, is_loading
|
214 |
|
215 |
def load_previous(tag, current_index, feed_items):
|
216 |
"""
|
|
|
226 |
"""
|
227 |
if current_index > 0:
|
228 |
current_index -= 1
|
229 |
+
html_content = generate_html(feed_items, False, current_index, tag, False)
|
230 |
+
return tag, current_index, feed_items, html_content, False
|
231 |
|
232 |
def generate_html(feed_items, scroll_to_latest=False, current_index=0, tag="", is_loading=False):
|
233 |
"""
|