tahirsher commited on
Commit
2c7d942
·
verified ·
1 Parent(s): d8997e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
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 the generated text into sentences using both "." and other common delimiters
9
- steps = text.replace("\n", " ").split('.')
10
-
11
- # Remove any extra spaces and filter out empty or repetitive steps
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
- if step and step.lower() not in seen_steps: # Skip empty or repetitive steps
 
18
  cleaned_steps.append(step)
19
- seen_steps.add(step.lower()) # Add step to the seen set
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