TeckWWW commited on
Commit
1d0d802
·
verified ·
1 Parent(s): 1a7d199

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -32
app.py CHANGED
@@ -264,41 +264,42 @@ class FixedRecipeAssistant:
264
  return 30 # Default
265
 
266
  def extract_instructions(self, row):
267
- """Extract instructions from 'RecipeInstructions' column"""
268
- instructions = row.get('RecipeInstructions')
269
-
270
- if pd.notna(instructions):
271
- try:
272
- instructions_str = str(instructions).strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
 
274
- # Handle R-style vector: c("step1", "step2", ...)
275
- if instructions_str.startswith('c('):
276
- try:
277
- cleaned = instructions_str.replace('c(', '').rstrip(')')
278
- steps = [s.strip().strip('"') for s in cleaned.split(',')]
279
- return '\n'.join([f"{i+1}. {s}" for i, s in enumerate(steps)])
280
- except:
281
- pass
282
 
283
- # Handle JSON-style list: ["step1", "step2"] or [{"text": "..."}]
284
- if instructions_str.startswith('['):
285
- steps = ast.literal_eval(instructions_str)
286
- if isinstance(steps, list):
287
- numbered_steps = []
288
- for i, step in enumerate(steps, 1):
289
- if isinstance(step, dict) and 'text' in step:
290
- numbered_steps.append(f"{i}. {step['text']}")
291
- else:
292
- numbered_steps.append(f"{i}. {str(step)}")
293
- return '\n'.join(numbered_steps)
294
-
295
- # Default fallback: plain text
296
- return instructions_str[:500] + "..." if len(instructions_str) > 500 else instructions_str
297
-
298
- except Exception as e:
299
- return str(instructions)[:500] + "..." if len(str(instructions)) > 500 else str(instructions)
300
 
301
- return "Instructions not available"
302
 
303
 
304
  def extract_rating(self, row):
 
264
  return 30 # Default
265
 
266
  def extract_instructions(self, row):
267
+ """Extract instructions from 'RecipeInstructions' column"""
268
+ instructions = row.get('RecipeInstructions')
269
+
270
+ if pd.notna(instructions):
271
+ try:
272
+ instructions_str = str(instructions).strip()
273
+
274
+ # Handle R-style vector: c("step1", "step2", ...)
275
+ if instructions_str.startswith('c('):
276
+ try:
277
+ cleaned = instructions_str.replace('c(', '').rstrip(')')
278
+ steps = [s.strip().strip('"') for s in cleaned.split(',')]
279
+ return '\n'.join([f"{i+1}. {s}" for i, s in enumerate(steps)])
280
+ except:
281
+ pass
282
+
283
+ # Handle JSON-style list: ["step1", "step2"] or [{"text": "..."}]
284
+ if instructions_str.startswith('['):
285
+ steps = ast.literal_eval(instructions_str)
286
+ if isinstance(steps, list):
287
+ numbered_steps = []
288
+ for i, step in enumerate(steps, 1):
289
+ if isinstance(step, dict) and 'text' in step:
290
+ numbered_steps.append(f"{i}. {step['text']}")
291
+ else:
292
+ numbered_steps.append(f"{i}. {str(step)}")
293
+ return '\n'.join(numbered_steps)
294
+
295
+ # Default fallback: plain text
296
+ return instructions_str[:500] + "..." if len(instructions_str) > 500 else instructions_str
297
 
298
+ except Exception as e:
299
+ return str(instructions)[:500] + "..." if len(str(instructions)) > 500 else str(instructions)
 
 
 
 
 
 
300
 
301
+ return "Instructions not available"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
 
 
303
 
304
 
305
  def extract_rating(self, row):