Liori25 commited on
Commit
f145dfd
·
verified ·
1 Parent(s): dab9d95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -5
app.py CHANGED
@@ -97,14 +97,24 @@ def find_similar_recipes_list(query_text):
97
 
98
  results_list = []
99
 
100
- # --- HELPER TO CHECK FOR ERRORS ---
101
  def clean_and_validate(raw_text):
102
  val = str(raw_text).strip()
 
 
103
  if val.startswith("[") and val.endswith("]"):
104
  val = val[1:-1].replace("'", "").replace('"', "").strip()
 
105
  val_lower = val.lower()
106
- if val_lower in ['nan', 'none', 'null', '[]', '', 'error']:
 
 
 
 
 
 
107
  return None
 
108
  return val
109
 
110
  for idx in top_indices:
@@ -115,17 +125,30 @@ def find_similar_recipes_list(query_text):
115
 
116
  content_parts = []
117
 
 
118
  if ing_col:
119
  cleaned_ing = clean_and_validate(row[ing_col])
120
- if cleaned_ing: content_parts.append(f"<b>🛒 INGREDIENTS:</b><br>{cleaned_ing}")
 
 
121
 
 
122
  if inst_col:
123
  cleaned_inst = clean_and_validate(row[inst_col])
124
- if cleaned_inst: content_parts.append(f"<b>🍳 INSTRUCTIONS:</b><br>{cleaned_inst}")
 
 
125
 
 
126
  if not content_parts:
 
127
  raw_out = str(row.get('Raw_Output', 'No details available.'))
128
- display_text = raw_out if "error" not in raw_out.lower() else "<i>Details unavailable.</i>"
 
 
 
 
 
129
  else:
130
  display_text = "<br><br>".join(content_parts)
131
 
 
97
 
98
  results_list = []
99
 
100
+ # --- HELPER TO CHECK FOR ERRORS & HIDE BLOCKS ---
101
  def clean_and_validate(raw_text):
102
  val = str(raw_text).strip()
103
+
104
+ # 1. Clean list syntax (['...'])
105
  if val.startswith("[") and val.endswith("]"):
106
  val = val[1:-1].replace("'", "").replace('"', "").strip()
107
+
108
  val_lower = val.lower()
109
+
110
+ # 2. Basic Empty Checks
111
+ if val_lower in ['nan', 'none', 'null', '[]', '']:
112
+ return None
113
+
114
+ # 3. STRICT ERROR CHECK: If "parse error" or "error" is in the text, return None to hide the block
115
+ if "parse error" in val_lower or "error" in val_lower:
116
  return None
117
+
118
  return val
119
 
120
  for idx in top_indices:
 
125
 
126
  content_parts = []
127
 
128
+ # 1. Check Ingredients
129
  if ing_col:
130
  cleaned_ing = clean_and_validate(row[ing_col])
131
+ # Only add to display if valid AND no error found
132
+ if cleaned_ing:
133
+ content_parts.append(f"<b>🛒 INGREDIENTS:</b><br>{cleaned_ing}")
134
 
135
+ # 2. Check Instructions
136
  if inst_col:
137
  cleaned_inst = clean_and_validate(row[inst_col])
138
+ # Only add to display if valid AND no error found
139
+ if cleaned_inst:
140
+ content_parts.append(f"<b>🍳 INSTRUCTIONS:</b><br>{cleaned_inst}")
141
 
142
+ # 3. Fallback logic
143
  if not content_parts:
144
+ # If both were hidden (due to errors) or empty, check raw output
145
  raw_out = str(row.get('Raw_Output', 'No details available.'))
146
+
147
+ # Also hide Raw Output if it contains an error
148
+ if "parse error" in raw_out.lower() or "error" in raw_out.lower():
149
+ display_text = "<i>Details unavailable for this recipe.</i>"
150
+ else:
151
+ display_text = raw_out
152
  else:
153
  display_text = "<br><br>".join(content_parts)
154