Coots commited on
Commit
25c77af
ยท
verified ยท
1 Parent(s): bb5ec5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -31,7 +31,7 @@ def translate(text, lang="en"):
31
 
32
  def extract_tile_area(msg, unit):
33
  msg = msg.lower().replace("feet", "").replace("ft", "").replace("mm", "").strip()
34
- msg = re.sub(r"\s*(x|ร—|\*|into)\s*", "x", msg)
35
  parts = msg.split("x")
36
 
37
  try:
@@ -60,6 +60,10 @@ def chat_fn(message, history, user_state={}):
60
  lang = user_state["lang"]
61
  def reply(text): return translate(text, lang)
62
 
 
 
 
 
63
  # Start conversation
64
  if "step" not in user_state:
65
  if message.lower() in ["floor", "wall"]:
@@ -96,7 +100,7 @@ def chat_fn(message, history, user_state={}):
96
  if user_state["step"] == "get_tile_size":
97
  area = extract_tile_area(message, user_state["unit"])
98
  if not area or area <= 0:
99
- return reply("โŒ That tile size didnโ€™t work. Try something like:\n- `600 x 600`\n- `2 x 2`\n- `4` (if in ft)"), None, user_state
100
 
101
  user_state["tile_area"] = area
102
  user_state["step"] = "done"
@@ -125,19 +129,18 @@ def chat_fn(message, history, user_state={}):
125
  top3 = best[:3]
126
 
127
  summary = f"""
128
- ๐Ÿงฑ Tile Type: {tile_type}
129
- ๐Ÿ“ Space: {user_state['length']} ft x {user_state['width']} ft
130
- ๐Ÿ“ Area to Cover: {area_needed} sq.ft
131
- ๐Ÿงฎ Tile Size Area: {round(area, 2)} sq.ft
132
- ๐Ÿ”ข Estimated Tiles Needed: {tile_needed} (with 10% buffer)
133
 
134
- ๐ŸŽฏ Top Suggestions:
135
  """
136
  for i, t in enumerate(top3, 1):
137
  summary += f"\n{i}. {t['name']} ({t['size']})\n โ‚น{t['price']} per box โ†’ ~{t['boxes']} boxes\n {t['url']}\n"
138
 
139
  summary += "\nType 'Floor' or 'Wall' to start another estimate."
140
-
141
  return reply(summary), None, user_state
142
 
143
  return reply("I didn't understand that. Please continue or type 'Floor' or 'Wall' to start over."), None, user_state
@@ -149,8 +152,8 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", radius_size="lg")) as de
149
  # ๐Ÿงฑ <span style="color:#3B82F6">TileBot</span> โ€“ Smart Tile Estimator
150
  Welcome! I'm here to help you estimate tiles for your floor or wall.
151
 
152
- ๐Ÿ‘‰ Start with **"Floor"** or **"Wall"**
153
- ๐Ÿ“ Enter **length and width** (in feet)
154
  ๐Ÿ“ Then your tile size (in `mm` or `ft`) โ€“ like `600 x 600`, `2x2`, or `4`
155
  ๐Ÿ“‹ Iโ€™ll recommend tiles and calculate how many you need.
156
  """,
 
31
 
32
  def extract_tile_area(msg, unit):
33
  msg = msg.lower().replace("feet", "").replace("ft", "").replace("mm", "").strip()
34
+ msg = re.sub(r"\s*(x|\u00d7|\*|into)\s*", "x", msg)
35
  parts = msg.split("x")
36
 
37
  try:
 
60
  lang = user_state["lang"]
61
  def reply(text): return translate(text, lang)
62
 
63
+ # Greeting handling
64
+ if message.strip().lower() in ["hi", "hello", "hey", "start", "tile", "help"]:
65
+ return reply("\U0001F44B Hello! I'm TileBot, your assistant for tile estimates.\nAre you planning for Floor or Wall tiles?"), None, user_state
66
+
67
  # Start conversation
68
  if "step" not in user_state:
69
  if message.lower() in ["floor", "wall"]:
 
100
  if user_state["step"] == "get_tile_size":
101
  area = extract_tile_area(message, user_state["unit"])
102
  if not area or area <= 0:
103
+ return reply("\u274C That tile size didnโ€™t work. Try something like:\n- `600 x 600`\n- `2 x 2`\n- `4` (if in ft)"), None, user_state
104
 
105
  user_state["tile_area"] = area
106
  user_state["step"] = "done"
 
129
  top3 = best[:3]
130
 
131
  summary = f"""
132
+ \U0001F9F1 Tile Type: {tile_type}
133
+ \U0001F4D0 Space: {user_state['length']} ft x {user_state['width']} ft
134
+ \U0001F4CF Area to Cover: {area_needed} sq.ft
135
+ \U0001F9EE Tile Size Area: {round(area, 2)} sq.ft
136
+ \U0001F522 Estimated Tiles Needed: {tile_needed} (with 10% buffer)
137
 
138
+ \U0001F3AF Top Suggestions:
139
  """
140
  for i, t in enumerate(top3, 1):
141
  summary += f"\n{i}. {t['name']} ({t['size']})\n โ‚น{t['price']} per box โ†’ ~{t['boxes']} boxes\n {t['url']}\n"
142
 
143
  summary += "\nType 'Floor' or 'Wall' to start another estimate."
 
144
  return reply(summary), None, user_state
145
 
146
  return reply("I didn't understand that. Please continue or type 'Floor' or 'Wall' to start over."), None, user_state
 
152
  # ๐Ÿงฑ <span style="color:#3B82F6">TileBot</span> โ€“ Smart Tile Estimator
153
  Welcome! I'm here to help you estimate tiles for your floor or wall.
154
 
155
+ ๐Ÿ”น Start with **"Floor"** or **"Wall"**
156
+ ๐Ÿ“€ Enter **length and width** (in feet)
157
  ๐Ÿ“ Then your tile size (in `mm` or `ft`) โ€“ like `600 x 600`, `2x2`, or `4`
158
  ๐Ÿ“‹ Iโ€™ll recommend tiles and calculate how many you need.
159
  """,