Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -131,15 +131,14 @@ def search_spaces(search_text, category):
|
|
131 |
<div style='margin-bottom: 20px; padding: 10px; background-color: var(--color-background-primary);
|
132 |
border: 1px solid var(--color-border-primary); border-radius: 5px;'>
|
133 |
<h3 style='color: var(--color-text-primary);'>Statistics:</h3>
|
134 |
-
<p style='color: var(--color-text-primary);'>
|
135 |
<p style='color: var(--color-text-primary);'>Total Likes: {total_likes:,}</p>
|
136 |
</div>
|
137 |
-
<div style='max-height: 800px; overflow-y: auto;'>
|
138 |
<div style='display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 10px;'>
|
139 |
"""
|
140 |
|
141 |
for _, row in spaces.iterrows():
|
142 |
-
# In the search_spaces function, update the card HTML template:
|
143 |
html_content += f"""
|
144 |
<div style='padding: 15px;
|
145 |
border: 2px solid var(--color-border-primary);
|
@@ -177,11 +176,31 @@ def search_spaces(search_text, category):
|
|
177 |
</div>
|
178 |
"""
|
179 |
|
180 |
-
html_content += "</div
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
return html_content
|
182 |
|
183 |
-
# Create the Gradio interface
|
184 |
def create_app():
|
|
|
|
|
185 |
with gr.Blocks(
|
186 |
title="Hugging Face Spaces Explorer",
|
187 |
theme=gr.themes.Soft(
|
@@ -213,21 +232,42 @@ def create_app():
|
|
213 |
|
214 |
# Display area for spaces
|
215 |
spaces_display = gr.HTML(value=search_spaces("", "All Categories"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
# Update display when category or search changes
|
218 |
category_dropdown.change(
|
219 |
-
fn=search_spaces,
|
220 |
-
inputs=[search_input, category_dropdown],
|
221 |
-
outputs=spaces_display
|
222 |
)
|
223 |
search_input.change(
|
224 |
-
fn=search_spaces,
|
225 |
-
inputs=[search_input, category_dropdown],
|
226 |
-
outputs=spaces_display
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
)
|
228 |
|
229 |
return app
|
230 |
|
|
|
231 |
# Launch the app
|
232 |
app = create_app()
|
233 |
-
app.launch(share=True)
|
|
|
131 |
<div style='margin-bottom: 20px; padding: 10px; background-color: var(--color-background-primary);
|
132 |
border: 1px solid var(--color-border-primary); border-radius: 5px;'>
|
133 |
<h3 style='color: var(--color-text-primary);'>Statistics:</h3>
|
134 |
+
<p style='color: var(--color-text-primary);'>Showing {min(offset + page_size, total_spaces)} of {total_spaces} Spaces</p>
|
135 |
<p style='color: var(--color-text-primary);'>Total Likes: {total_likes:,}</p>
|
136 |
</div>
|
137 |
+
<div style='max-height: 800px; overflow-y: auto;' id='spaces-container'>
|
138 |
<div style='display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 10px;'>
|
139 |
"""
|
140 |
|
141 |
for _, row in spaces.iterrows():
|
|
|
142 |
html_content += f"""
|
143 |
<div style='padding: 15px;
|
144 |
border: 2px solid var(--color-border-primary);
|
|
|
176 |
</div>
|
177 |
"""
|
178 |
|
179 |
+
html_content += "</div>"
|
180 |
+
|
181 |
+
# Add Load More button if there are more spaces
|
182 |
+
if offset + page_size < total_spaces:
|
183 |
+
html_content += f"""
|
184 |
+
<div style='text-align: center; padding: 20px;'>
|
185 |
+
<button onclick='window.loadMore()'
|
186 |
+
style='padding: 10px 20px;
|
187 |
+
background-color: #2196F3;
|
188 |
+
color: white;
|
189 |
+
border: none;
|
190 |
+
border-radius: 5px;
|
191 |
+
cursor: pointer;
|
192 |
+
font-size: 1em;'>
|
193 |
+
Load More ({total_spaces - (offset + page_size)} remaining)
|
194 |
+
</button>
|
195 |
+
</div>
|
196 |
+
"""
|
197 |
+
|
198 |
+
html_content += "</div>"
|
199 |
return html_content
|
200 |
|
|
|
201 |
def create_app():
|
202 |
+
current_offset = gr.State(value=0)
|
203 |
+
|
204 |
with gr.Blocks(
|
205 |
title="Hugging Face Spaces Explorer",
|
206 |
theme=gr.themes.Soft(
|
|
|
232 |
|
233 |
# Display area for spaces
|
234 |
spaces_display = gr.HTML(value=search_spaces("", "All Categories"))
|
235 |
+
|
236 |
+
def load_more(search_text, category, offset):
|
237 |
+
new_offset = offset + 30
|
238 |
+
return search_spaces(search_text, category, new_offset), new_offset
|
239 |
+
|
240 |
+
# JavaScript for handling the Load More button
|
241 |
+
app.load(None, None, None, _js="""
|
242 |
+
function loadMore() {
|
243 |
+
const event = new CustomEvent('load_more');
|
244 |
+
document.dispatchEvent(event);
|
245 |
+
}
|
246 |
+
""")
|
247 |
|
248 |
# Update display when category or search changes
|
249 |
category_dropdown.change(
|
250 |
+
fn=lambda x, y, _: (search_spaces(x, y), 0),
|
251 |
+
inputs=[search_input, category_dropdown, current_offset],
|
252 |
+
outputs=[spaces_display, current_offset]
|
253 |
)
|
254 |
search_input.change(
|
255 |
+
fn=lambda x, y, _: (search_spaces(x, y), 0),
|
256 |
+
inputs=[search_input, category_dropdown, current_offset],
|
257 |
+
outputs=[spaces_display, current_offset]
|
258 |
+
)
|
259 |
+
|
260 |
+
# Load More event handler
|
261 |
+
app.load(
|
262 |
+
fn=load_more,
|
263 |
+
inputs=[search_input, category_dropdown, current_offset],
|
264 |
+
outputs=[spaces_display, current_offset],
|
265 |
+
_js="(x) => document.addEventListener('load_more', () => x())"
|
266 |
)
|
267 |
|
268 |
return app
|
269 |
|
270 |
+
|
271 |
# Launch the app
|
272 |
app = create_app()
|
273 |
+
app.launch('share=True')
|