Spaces:
Sleeping
Sleeping
Create utils.py
Browse files
utils.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import fitz # PyMuPDF
|
| 2 |
+
|
| 3 |
+
def extract_text_from_pdfs(folder_path="meal_plans"):
|
| 4 |
+
import os
|
| 5 |
+
texts = []
|
| 6 |
+
for file_name in os.listdir(folder_path):
|
| 7 |
+
if file_name.endswith(".pdf"):
|
| 8 |
+
doc = fitz.open(os.path.join(folder_path, file_name))
|
| 9 |
+
text = "\n".join([page.get_text() for page in doc])
|
| 10 |
+
texts.append(text)
|
| 11 |
+
return "\n\n".join(texts)
|
| 12 |
+
|
| 13 |
+
def format_chat(history, new_input):
|
| 14 |
+
return "\n".join([f"User: {inp}\nBot: {out}" for inp, out in history] + [f"User: {new_input}"])
|