Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -88,7 +88,7 @@ def render_products(products):
|
|
| 88 |
<a href="{url}" target="_blank">View Product</a>
|
| 89 |
</div>
|
| 90 |
"""
|
| 91 |
-
return html
|
| 92 |
|
| 93 |
# --- Filters, search, sort ---
|
| 94 |
def get_filtered_products(category="All", sort_by="Rating", min_price=0, max_price=1000, in_stock=False, query=""):
|
|
@@ -135,6 +135,12 @@ def load_more(category, sort_by, min_price, max_price, in_stock, query):
|
|
| 135 |
shown_products = pd.concat([pd.DataFrame(shown_products), next_batch])
|
| 136 |
return render_products(shown_products)
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
# --- Quote Slideshow ---
|
| 139 |
current_quote = [random.choice(quotes)]
|
| 140 |
|
|
@@ -150,10 +156,10 @@ threading.Thread(target=cycle_quotes, daemon=True).start()
|
|
| 150 |
|
| 151 |
# --- Gradio UI ---
|
| 152 |
with gr.Blocks(css="""
|
| 153 |
-
body {background: #0d1117; color: #e6edf3; font-family: 'Segoe UI', sans-serif;}
|
| 154 |
.grid-container {
|
| 155 |
display: grid;
|
| 156 |
-
grid-template-columns: repeat(auto-
|
| 157 |
gap: 15px;
|
| 158 |
justify-items: center;
|
| 159 |
}
|
|
@@ -190,7 +196,6 @@ body {background: #0d1117; color: #e6edf3; font-family: 'Segoe UI', sans-serif;}
|
|
| 190 |
left: 100%;
|
| 191 |
margin-left: 10px;
|
| 192 |
}
|
| 193 |
-
/* Adjust if near right edge */
|
| 194 |
@media(max-width: 1024px) {
|
| 195 |
.card:hover::after {
|
| 196 |
left: auto;
|
|
@@ -214,29 +219,28 @@ a:hover {text-decoration: underline;}
|
|
| 214 |
.quote-box {padding: 12px; margin: 10px 0; background: rgba(0,255,100,0.1); border-left: 4px solid #39ff14; font-style: italic; border-radius: 8px; text-align:center;}
|
| 215 |
.impact {color: #ffd700; margin-top: 6px; font-size: 0.9em;}
|
| 216 |
""") as demo:
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
# QUOTE SLIDESHOW
|
| 220 |
-
with gr.Row():
|
| 221 |
-
quote_output = gr.HTML()
|
| 222 |
-
|
| 223 |
-
demo.load(get_quote, None, quote_output)
|
| 224 |
-
|
| 225 |
-
# Filters
|
| 226 |
with gr.Row():
|
|
|
|
| 227 |
category = gr.Dropdown(["All"] + sorted(df["category"].dropna().unique().tolist()), label="Category")
|
| 228 |
sort_by = gr.Dropdown(["Price: Low to High", "Price: High to Low", "Rating"], label="Sort By", value="Rating")
|
| 229 |
-
|
| 230 |
-
with gr.Row():
|
| 231 |
min_price = gr.Number(label="Min Price", value=0)
|
| 232 |
max_price = gr.Number(label="Max Price", value=1000)
|
| 233 |
in_stock = gr.Checkbox(label="In Stock Only")
|
| 234 |
-
|
| 235 |
-
|
| 236 |
show_btn = gr.Button("π Show Products")
|
| 237 |
load_more_btn = gr.Button("β Load More")
|
| 238 |
output = gr.HTML()
|
| 239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
show_btn.click(show_products, [category, sort_by, min_price, max_price, in_stock, query], output)
|
| 241 |
load_more_btn.click(load_more, [category, sort_by, min_price, max_price, in_stock, query], output)
|
| 242 |
|
|
|
|
| 88 |
<a href="{url}" target="_blank">View Product</a>
|
| 89 |
</div>
|
| 90 |
"""
|
| 91 |
+
return f"<div class='grid-container'>{html}</div>"
|
| 92 |
|
| 93 |
# --- Filters, search, sort ---
|
| 94 |
def get_filtered_products(category="All", sort_by="Rating", min_price=0, max_price=1000, in_stock=False, query=""):
|
|
|
|
| 135 |
shown_products = pd.concat([pd.DataFrame(shown_products), next_batch])
|
| 136 |
return render_products(shown_products)
|
| 137 |
|
| 138 |
+
# --- Random products on start ---
|
| 139 |
+
def show_random_products():
|
| 140 |
+
global shown_products
|
| 141 |
+
shown_products = df.sample(n=batch_size)
|
| 142 |
+
return render_products(shown_products)
|
| 143 |
+
|
| 144 |
# --- Quote Slideshow ---
|
| 145 |
current_quote = [random.choice(quotes)]
|
| 146 |
|
|
|
|
| 156 |
|
| 157 |
# --- Gradio UI ---
|
| 158 |
with gr.Blocks(css="""
|
| 159 |
+
body {background: #0d1117; color: #e6edf3; font-family: 'Segoe UI', sans-serif; margin:0; padding:0;}
|
| 160 |
.grid-container {
|
| 161 |
display: grid;
|
| 162 |
+
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
| 163 |
gap: 15px;
|
| 164 |
justify-items: center;
|
| 165 |
}
|
|
|
|
| 196 |
left: 100%;
|
| 197 |
margin-left: 10px;
|
| 198 |
}
|
|
|
|
| 199 |
@media(max-width: 1024px) {
|
| 200 |
.card:hover::after {
|
| 201 |
left: auto;
|
|
|
|
| 219 |
.quote-box {padding: 12px; margin: 10px 0; background: rgba(0,255,100,0.1); border-left: 4px solid #39ff14; font-style: italic; border-radius: 8px; text-align:center;}
|
| 220 |
.impact {color: #ffd700; margin-top: 6px; font-size: 0.9em;}
|
| 221 |
""") as demo:
|
| 222 |
+
|
| 223 |
+
# Search & filters on top
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
with gr.Row():
|
| 225 |
+
query = gr.Textbox(label="Search")
|
| 226 |
category = gr.Dropdown(["All"] + sorted(df["category"].dropna().unique().tolist()), label="Category")
|
| 227 |
sort_by = gr.Dropdown(["Price: Low to High", "Price: High to Low", "Rating"], label="Sort By", value="Rating")
|
|
|
|
|
|
|
| 228 |
min_price = gr.Number(label="Min Price", value=0)
|
| 229 |
max_price = gr.Number(label="Max Price", value=1000)
|
| 230 |
in_stock = gr.Checkbox(label="In Stock Only")
|
| 231 |
+
|
|
|
|
| 232 |
show_btn = gr.Button("π Show Products")
|
| 233 |
load_more_btn = gr.Button("β Load More")
|
| 234 |
output = gr.HTML()
|
| 235 |
|
| 236 |
+
# Quote row
|
| 237 |
+
with gr.Row():
|
| 238 |
+
quote_output = gr.HTML()
|
| 239 |
+
demo.load(get_quote, None, quote_output)
|
| 240 |
+
|
| 241 |
+
# Show random products on page load
|
| 242 |
+
demo.load(show_random_products, None, output)
|
| 243 |
+
|
| 244 |
show_btn.click(show_products, [category, sort_by, min_price, max_price, in_stock, query], output)
|
| 245 |
load_more_btn.click(load_more, [category, sort_by, min_price, max_price, in_stock, query], output)
|
| 246 |
|