Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -111,7 +111,7 @@ df['url'] = 'https://huggingface.co/spaces/' + df['id']
|
|
111 |
|
112 |
# ------------------------------------------------------
|
113 |
|
114 |
-
def search_spaces(search_text="", category="All Categories", offset=0, page_size=
|
115 |
if category == "All Categories":
|
116 |
spaces_df = df
|
117 |
else:
|
@@ -183,16 +183,9 @@ def search_spaces(search_text="", category="All Categories", offset=0, page_size
|
|
183 |
if offset + page_size < total_spaces:
|
184 |
html_content += f"""
|
185 |
<div style='text-align: center; padding: 20px;'>
|
186 |
-
<
|
187 |
-
|
188 |
-
|
189 |
-
color: white;
|
190 |
-
border: none;
|
191 |
-
border-radius: 5px;
|
192 |
-
cursor: pointer;
|
193 |
-
font-size: 1em;'>
|
194 |
-
Load More ({total_spaces - (offset + page_size)} remaining)
|
195 |
-
</button>
|
196 |
</div>
|
197 |
"""
|
198 |
|
@@ -219,32 +212,22 @@ def create_app():
|
|
219 |
|
220 |
with gr.Row():
|
221 |
with gr.Column(scale=1):
|
222 |
-
# Category selection
|
223 |
category_dropdown = gr.Dropdown(
|
224 |
choices=["All Categories"] + sorted(df['category'].unique()),
|
225 |
label="Select Category",
|
226 |
value="All Categories"
|
227 |
)
|
228 |
-
# Search box
|
229 |
search_input = gr.Textbox(
|
230 |
label="Search Spaces",
|
231 |
placeholder="Enter search terms..."
|
232 |
)
|
233 |
|
234 |
-
# Display area for spaces
|
235 |
spaces_display = gr.HTML(value=search_spaces("", "All Categories"))
|
236 |
-
|
|
|
237 |
def load_more(search_text, category, offset):
|
238 |
new_offset = offset + 30
|
239 |
return search_spaces(search_text, category, new_offset), new_offset
|
240 |
-
|
241 |
-
# JavaScript for handling the Load More button
|
242 |
-
app.load(None, None, None, _js="""
|
243 |
-
function loadMore() {
|
244 |
-
const event = new CustomEvent('load_more');
|
245 |
-
document.dispatchEvent(event);
|
246 |
-
}
|
247 |
-
""")
|
248 |
|
249 |
# Update display when category or search changes
|
250 |
category_dropdown.change(
|
@@ -258,12 +241,11 @@ def create_app():
|
|
258 |
outputs=[spaces_display, current_offset]
|
259 |
)
|
260 |
|
261 |
-
# Load More
|
262 |
-
|
263 |
fn=load_more,
|
264 |
inputs=[search_input, category_dropdown, current_offset],
|
265 |
-
outputs=[spaces_display, current_offset]
|
266 |
-
_js="(x) => document.addEventListener('load_more', () => x())"
|
267 |
)
|
268 |
|
269 |
return app
|
|
|
111 |
|
112 |
# ------------------------------------------------------
|
113 |
|
114 |
+
def search_spaces(search_text="", category="All Categories", offset=0, page_size=100):
|
115 |
if category == "All Categories":
|
116 |
spaces_df = df
|
117 |
else:
|
|
|
183 |
if offset + page_size < total_spaces:
|
184 |
html_content += f"""
|
185 |
<div style='text-align: center; padding: 20px;'>
|
186 |
+
<p style='color: var(--color-text-primary);'>
|
187 |
+
{total_spaces - (offset + page_size)} more spaces available
|
188 |
+
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
</div>
|
190 |
"""
|
191 |
|
|
|
212 |
|
213 |
with gr.Row():
|
214 |
with gr.Column(scale=1):
|
|
|
215 |
category_dropdown = gr.Dropdown(
|
216 |
choices=["All Categories"] + sorted(df['category'].unique()),
|
217 |
label="Select Category",
|
218 |
value="All Categories"
|
219 |
)
|
|
|
220 |
search_input = gr.Textbox(
|
221 |
label="Search Spaces",
|
222 |
placeholder="Enter search terms..."
|
223 |
)
|
224 |
|
|
|
225 |
spaces_display = gr.HTML(value=search_spaces("", "All Categories"))
|
226 |
+
load_more_btn = gr.Button("Load More", visible=False)
|
227 |
+
|
228 |
def load_more(search_text, category, offset):
|
229 |
new_offset = offset + 30
|
230 |
return search_spaces(search_text, category, new_offset), new_offset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
|
232 |
# Update display when category or search changes
|
233 |
category_dropdown.change(
|
|
|
241 |
outputs=[spaces_display, current_offset]
|
242 |
)
|
243 |
|
244 |
+
# Load More button handler
|
245 |
+
load_more_btn.click(
|
246 |
fn=load_more,
|
247 |
inputs=[search_input, category_dropdown, current_offset],
|
248 |
+
outputs=[spaces_display, current_offset]
|
|
|
249 |
)
|
250 |
|
251 |
return app
|