Spaces:
Running
Running
File size: 1,225 Bytes
efdcdc4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
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}"
|