Spaces:
Running
Running
import pandas as pd | |
import gradio as gr | |
def get_quantities_from_csv(path): | |
try: | |
df = pd.read_csv(path) | |
if df.empty or "Quantity" not in df.columns: | |
return gr.update(choices=[], visible=False), {} | |
return gr.update(choices=df["Quantity"].dropna().tolist(), visible=True), df.to_dict() | |
except Exception as e: | |
print(f"β Error loading CSV: {e}") | |
return gr.update(choices=[], visible=False), {} | |
def display_quantity_info(quantity, data_dict): | |
try: | |
df = pd.DataFrame(data_dict) | |
row = df[df["Quantity"] == quantity].iloc[0] | |
if str(row["In Stock"]).strip().lower() == "yes": | |
msg = ( | |
f"β {quantity} is available!\n" | |
f"β’ Floor: {row['Floor']}\n" | |
f"β’ Aisle: {row['Aisle']}\n" | |
f"β’ Price: βΉ{row['Price']}" | |
) | |
if "Offer" in row and pd.notna(row["Offer"]) and row["Offer"].strip(): | |
msg += f"\nβ’ π Offer: {row['Offer']}" | |
return msg | |
else: | |
return f"β Sorry, {quantity} is currently not in stock." | |
except Exception as e: | |
return f"β Error: {e}" | |