Chris4K commited on
Commit
b3030b4
·
verified ·
1 Parent(s): 0351ee1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -100,17 +100,13 @@ def calculate_statistics(embeddings):
100
  return {"tokens": len(embeddings), "time_taken": time.time()}
101
 
102
  import shutil
103
-
104
-
105
  def upload_file(file, model_name, split_strategy, chunk_size, overlap_size, max_tokens, query, top_k):
106
- #fh = open(file, 'r')
107
- #data = fh.readlines()
108
- # Write the file using file.read() instead of file.value
109
- #with open(os.path.join(FILES_DIR, file.name), "wb") as f:
110
- # f.write(data) # Use .read() to get the file content
111
  file_path = os.path.join(FILES_DIR, file.name)
112
 
113
- shutil.copyfile(file.name, file_path)
 
 
114
 
115
  # Process files and get embeddings
116
  embeddings, chunks = process_files(model_name, split_strategy, chunk_size, overlap_size, max_tokens)
@@ -123,6 +119,7 @@ def upload_file(file, model_name, split_strategy, chunk_size, overlap_size, max_
123
 
124
  return {"results": results, "stats": stats}
125
 
 
126
  # Gradio interface
127
  iface = gr.Interface(
128
  fn=upload_file,
 
100
  return {"tokens": len(embeddings), "time_taken": time.time()}
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
  embeddings, chunks = process_files(model_name, split_strategy, chunk_size, overlap_size, max_tokens)
 
119
 
120
  return {"results": results, "stats": stats}
121
 
122
+
123
  # Gradio interface
124
  iface = gr.Interface(
125
  fn=upload_file,