Zeeshan42 commited on
Commit
e85a115
·
verified ·
1 Parent(s): 36760e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
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": "/app/DSM5.pdf",
13
- "Personality": "/app/TheoriesofPersonality.pdf",
14
- "SearchForMeaning": "/app/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
- with open(path, "r", encoding="utf-8", errors='ignore') as file:
22
- text = file.read()
23
- paragraphs = text.split("\n\n") # Split by paragraphs (adjust as needed)
24
- for paragraph in paragraphs:
25
- if paragraph.strip(): # Skip empty paragraphs
26
- data.append({"text": paragraph.strip()})
 
 
 
 
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