shlokamhaisekar commited on
Commit
4c36b4a
·
verified ·
1 Parent(s): 06ea076

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py CHANGED
@@ -16,6 +16,35 @@ with open("recipes.txt", "r", encoding="utf-8") as file:
16
  # Print the text below
17
  print(recipes_text)
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def respond(message, history):
20
  #responses = ["Yes", "No"]
21
  #return random.choice(responses)
 
16
  # Print the text below
17
  print(recipes_text)
18
 
19
+ def preprocess_text(text):
20
+ # Strip extra whitespace from the beginning and the end of the text
21
+ cleaned_text = text.strip()
22
+
23
+ # Split the cleaned_text by every newline character (\n)
24
+ chunks = cleaned_text.split(".")
25
+
26
+ # Create an empty list to store cleaned chunks
27
+ cleaned_chunks = []
28
+
29
+ # Write your for-in loop below to clean each chunk and add it to the cleaned_chunks list
30
+ for chunk in chunks:
31
+ clean = chunk.strip()
32
+ if len(chunk)>0:
33
+ cleaned_chunks.append(clean)
34
+
35
+ # Print cleaned_chunks
36
+ print(cleaned_chunks)
37
+
38
+ # Print the length of cleaned_chunks
39
+
40
+ print(len(cleaned_chunks))
41
+
42
+ # Return the cleaned_chunks
43
+ return cleaned_chunks
44
+
45
+ # Call the preprocess_text function and store the result in a cleaned_chunks variable
46
+ cleaned_chunks = preprocess_text(recipes_text) # Complete this line
47
+
48
  def respond(message, history):
49
  #responses = ["Yes", "No"]
50
  #return random.choice(responses)