Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
#
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
# f.write(file.read()) # Read and write the file content
|
| 110 |
|
| 111 |
-
#
|
| 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 |
-
|
| 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 |
|