Chris4K commited on
Commit
e267239
1 Parent(s): 379c0eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -101,25 +101,20 @@ def calculate_statistics(embeddings):
101
 
102
  import shutil
103
  def upload_file(file, model_name, split_strategy, chunk_size, overlap_size, max_tokens, query, top_k):
104
- # Create the full destination file path
105
- #file_path = os.path.join(FILES_DIR, file.name)
106
-
107
- # Write the uploaded file content to the file path
108
- #with open(file_path, "wb") as f:
109
- # f.write(file.read()) # Read and write the file content
110
 
111
- # Process files and get embeddings
112
  try:
113
  chunk_size = int(chunk_size) # Convert chunk_size to int
114
  overlap_size = int(overlap_size) # Convert overlap_size to int
115
  except ValueError:
116
  return {"error": "Chunk size and overlap size must be valid integers."}
117
 
118
- if overlap_size is None:
119
- overlap_size = 0 # Set a default overlap size
120
- if chunk_size is None:
121
- chunk_size = 100 # Set a default chunk size
122
-
123
  embeddings, chunks = process_files(model_name, split_strategy, chunk_size, overlap_size, max_tokens)
124
 
125
  # Perform search
@@ -127,7 +122,7 @@ def upload_file(file, model_name, split_strategy, chunk_size, overlap_size, max_
127
 
128
  # Calculate statistics
129
  stats = calculate_statistics(embeddings)
130
-
131
  return {"results": results, "stats": stats}
132
 
133
 
 
101
 
102
  import shutil
103
  def upload_file(file, model_name, split_strategy, chunk_size, overlap_size, max_tokens, query, top_k):
104
+ # Ensure default values are set if None is passed
105
+ if chunk_size is None:
106
+ chunk_size = 100 # Set a default chunk size
107
+ if overlap_size is None:
108
+ overlap_size = 0 # Set a default overlap size
 
109
 
110
+ # Convert chunk_size and overlap_size to integers after checking for None
111
  try:
112
  chunk_size = int(chunk_size) # Convert chunk_size to int
113
  overlap_size = int(overlap_size) # Convert overlap_size to int
114
  except ValueError:
115
  return {"error": "Chunk size and overlap size must be valid integers."}
116
 
117
+ # Process files and get embeddings
 
 
 
 
118
  embeddings, chunks = process_files(model_name, split_strategy, chunk_size, overlap_size, max_tokens)
119
 
120
  # Perform search
 
122
 
123
  # Calculate statistics
124
  stats = calculate_statistics(embeddings)
125
+
126
  return {"results": results, "stats": stats}
127
 
128