Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -55,7 +55,47 @@ class VectorStore:
|
|
55 |
dataset = load_dataset('Thefoodprocessor/recipe_new_with_features_full')
|
56 |
vector_store = VectorStore("embedding_vector")
|
57 |
vector_store.populate_vectors(dataset)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
def generate_text(
|
60 |
message,
|
61 |
history: list[tuple[str, str]],
|
@@ -87,7 +127,7 @@ def generate_text(
|
|
87 |
stream=True,
|
88 |
)
|
89 |
for out in output:
|
90 |
-
temp += out["choices"][0]["text"]
|
91 |
yield temp
|
92 |
|
93 |
# Define the Gradio interface
|
|
|
55 |
dataset = load_dataset('Thefoodprocessor/recipe_new_with_features_full')
|
56 |
vector_store = VectorStore("embedding_vector")
|
57 |
vector_store.populate_vectors(dataset)
|
58 |
+
def format_recipe(input_string):
|
59 |
+
# Clean up the input
|
60 |
+
cleaned_text = input_string.strip("[]'").replace('\\n', '\n')
|
61 |
+
|
62 |
+
# Split the text into lines
|
63 |
+
lines = cleaned_text.split('\n')
|
64 |
+
|
65 |
+
# Initialize sections
|
66 |
+
title = lines[0]
|
67 |
+
ingredients = []
|
68 |
+
instructions = []
|
69 |
+
substitutions = []
|
70 |
|
71 |
+
# Extract ingredients and instructions
|
72 |
+
in_instructions = False
|
73 |
+
for line in lines[1:]:
|
74 |
+
if line.startswith("Instructions:"):
|
75 |
+
in_instructions = True
|
76 |
+
continue
|
77 |
+
|
78 |
+
if in_instructions:
|
79 |
+
if line.strip(): # Check for non-empty lines
|
80 |
+
instructions.append(line.strip())
|
81 |
+
else:
|
82 |
+
if line.strip(): # Check for non-empty lines
|
83 |
+
ingredients.append(line.strip())
|
84 |
+
|
85 |
+
# Gather substitutions from the last few lines
|
86 |
+
for line in lines:
|
87 |
+
if ':' in line:
|
88 |
+
substitutions.append(line.strip())
|
89 |
+
|
90 |
+
# Format output
|
91 |
+
formatted_recipe = f"## {title}\n\n### Ingredients:\n"
|
92 |
+
formatted_recipe += '\n'.join(f"- {item}" for item in ingredients) + "\n\n"
|
93 |
+
formatted_recipe += "### Instructions:\n" + '\n'.join(f"{i + 1}. {line}" for i, line in enumerate(instructions)) + "\n\n"
|
94 |
+
|
95 |
+
if substitutions:
|
96 |
+
formatted_recipe += "### Substitutions:\n" + '\n'.join(f"- **{line.split(':')[0].strip()}**: {line.split(':')[1].strip()}" for line in substitutions) + "\n"
|
97 |
+
return formatted_recipe
|
98 |
+
# print(formatted_recipe)
|
99 |
def generate_text(
|
100 |
message,
|
101 |
history: list[tuple[str, str]],
|
|
|
127 |
stream=True,
|
128 |
)
|
129 |
for out in output:
|
130 |
+
temp += format_recipe(out["choices"][0]["text"])
|
131 |
yield temp
|
132 |
|
133 |
# Define the Gradio interface
|