Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,23 +7,27 @@ import os
|
|
7 |
# Initialize Groq client with your API key
|
8 |
client = Groq(api_key="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")
|
9 |
|
10 |
-
# Paths to your books
|
11 |
book_paths = {
|
12 |
-
"DSM": "
|
13 |
-
"Personality": "
|
14 |
-
"SearchForMeaning": "
|
15 |
}
|
16 |
|
17 |
# Function to load and preprocess the data from books
|
18 |
def load_data(paths):
|
19 |
data = []
|
20 |
for title, path in paths.items():
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
return Dataset.from_list(data)
|
28 |
|
29 |
# Load and preprocess dataset for fine-tuning
|
|
|
7 |
# Initialize Groq client with your API key
|
8 |
client = Groq(api_key="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")
|
9 |
|
10 |
+
# Paths to your books (assuming files are in the root directory of the repo)
|
11 |
book_paths = {
|
12 |
+
"DSM": "./DSM5.pdf",
|
13 |
+
"Personality": "./TheoriesofPersonality.pdf",
|
14 |
+
"SearchForMeaning": "./MansSearchForMeaning.pdf"
|
15 |
}
|
16 |
|
17 |
# Function to load and preprocess the data from books
|
18 |
def load_data(paths):
|
19 |
data = []
|
20 |
for title, path in paths.items():
|
21 |
+
print(f"Attempting to load file for {title} from path: {path}")
|
22 |
+
try:
|
23 |
+
with open(path, "r", encoding="utf-8", errors='ignore') as file:
|
24 |
+
text = file.read()
|
25 |
+
paragraphs = text.split("\n\n") # Split by paragraphs (adjust as needed)
|
26 |
+
for paragraph in paragraphs:
|
27 |
+
if paragraph.strip(): # Skip empty paragraphs
|
28 |
+
data.append({"text": paragraph.strip()})
|
29 |
+
except FileNotFoundError:
|
30 |
+
print(f"Error: File for {title} not found at path {path}")
|
31 |
return Dataset.from_list(data)
|
32 |
|
33 |
# Load and preprocess dataset for fine-tuning
|