RetailGenie / utils /data_utils.py
Parishri07's picture
Upload 7 files
efdcdc4 verified
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}"