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}"