abhinavsunil commited on
Commit
c0c2a9f
·
verified ·
1 Parent(s): 57a34e2

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +14 -1
main.py CHANGED
@@ -48,6 +48,18 @@ def home():
48
 
49
 
50
  @app.get("/search")
 
 
 
 
 
 
 
 
 
 
 
 
51
  def search(query: str):
52
  query_vector = model.encode([query])
53
  faiss.normalize_L2(query_vector)
@@ -69,7 +81,8 @@ def search(query: str):
69
  else row["ingredients"]
70
  ),
71
  "calories": float(row["calories"]),
72
- "protein": float(row["protein"])
 
73
  })
74
 
75
  return {
 
48
 
49
 
50
  @app.get("/search")
51
+ def clean_instructions(instruction_input):
52
+ if isinstance(instruction_input, str) and instruction_input.startswith('c("'):
53
+
54
+ content = re.search(r'c\("(.*)"\)', instruction_input)
55
+ if content:
56
+ # Split by "," and clean quotes/whitespace
57
+ return [step.strip().strip('"') for step in content.group(1).split('", "')]
58
+
59
+ if isinstance(instruction_input, (list, np.ndarray)):
60
+ return list(instruction_input)
61
+
62
+ return [str(instruction_input)]
63
  def search(query: str):
64
  query_vector = model.encode([query])
65
  faiss.normalize_L2(query_vector)
 
81
  else row["ingredients"]
82
  ),
83
  "calories": float(row["calories"]),
84
+ "protein": float(row["protein"]),
85
+ "instructions": clean_instructions(row['RecipeInstructions'])
86
  })
87
 
88
  return {