Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,24 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
# Initialize the text generation pipeline with the GPT-2 fine-tuned recipe model
|
5 |
pipe = pipeline("text-generation", model="mrm8488/gpt2-finetuned-recipes-cooking_v2")
|
6 |
|
7 |
def clean_recipe(text):
|
8 |
-
# Split
|
9 |
-
steps =
|
10 |
-
|
11 |
-
# Remove any
|
12 |
cleaned_steps = []
|
13 |
seen_steps = set() # Track steps to avoid repetition
|
14 |
|
15 |
for step in steps:
|
16 |
step = step.strip() # Remove leading/trailing spaces
|
17 |
-
|
|
|
18 |
cleaned_steps.append(step)
|
19 |
-
seen_steps.add(step.lower()) #
|
20 |
|
21 |
return cleaned_steps
|
22 |
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
+
import re
|
4 |
|
5 |
# Initialize the text generation pipeline with the GPT-2 fine-tuned recipe model
|
6 |
pipe = pipeline("text-generation", model="mrm8488/gpt2-finetuned-recipes-cooking_v2")
|
7 |
|
8 |
def clean_recipe(text):
|
9 |
+
# Split text into sentences based on periods, question marks, or exclamation points
|
10 |
+
steps = re.split(r'(?<=[.!?])\s+', text)
|
11 |
+
|
12 |
+
# Remove any irrelevant or overly technical information by filtering based on length and content
|
13 |
cleaned_steps = []
|
14 |
seen_steps = set() # Track steps to avoid repetition
|
15 |
|
16 |
for step in steps:
|
17 |
step = step.strip() # Remove leading/trailing spaces
|
18 |
+
# Skip irrelevant or short steps and avoid repetitions
|
19 |
+
if len(step) > 20 and step.lower() not in seen_steps:
|
20 |
cleaned_steps.append(step)
|
21 |
+
seen_steps.add(step.lower()) # Track unique steps
|
22 |
|
23 |
return cleaned_steps
|
24 |
|