Update app.py
Browse files
app.py
CHANGED
@@ -101,8 +101,9 @@ def calculate_statistics(embeddings):
|
|
101 |
|
102 |
# Gradio frontend
|
103 |
def upload_file(file, model_name, split_strategy, chunk_size, overlap_size, max_tokens, query, top_k):
|
|
|
104 |
with open(os.path.join(FILES_DIR, file.name), "wb") as f:
|
105 |
-
f.write(file.value)
|
106 |
|
107 |
# Process files and get embeddings
|
108 |
embeddings, chunks = process_files(model_name, split_strategy, chunk_size, overlap_size, max_tokens)
|
@@ -115,17 +116,18 @@ def upload_file(file, model_name, split_strategy, chunk_size, overlap_size, max_
|
|
115 |
|
116 |
return {"results": results, "stats": stats}
|
117 |
|
|
|
118 |
# Gradio interface
|
119 |
iface = gr.Interface(
|
120 |
fn=upload_file,
|
121 |
inputs=[
|
122 |
gr.File(label="Upload File"),
|
|
|
123 |
gr.Dropdown(choices=list(MODELS.keys()), label="Embedding Model"),
|
124 |
gr.Radio(choices=["sentence", "recursive"], label="Split Strategy"),
|
125 |
gr.Slider(100, 1000, step=100, value=500, label="Chunk Size"),
|
126 |
gr.Slider(0, 100, step=10, value=50, label="Overlap Size"),
|
127 |
gr.Slider(50, 500, step=50, value=200, label="Max Tokens"),
|
128 |
-
gr.Textbox(label="Search Query"),
|
129 |
gr.Slider(1, 10, step=1, value=5, label="Top K")
|
130 |
],
|
131 |
outputs="json"
|
|
|
101 |
|
102 |
# Gradio frontend
|
103 |
def upload_file(file, model_name, split_strategy, chunk_size, overlap_size, max_tokens, query, top_k):
|
104 |
+
# Write the file using file.value instead of file.read()
|
105 |
with open(os.path.join(FILES_DIR, file.name), "wb") as f:
|
106 |
+
f.write(file.value) # Use .value to get the file content
|
107 |
|
108 |
# Process files and get embeddings
|
109 |
embeddings, chunks = process_files(model_name, split_strategy, chunk_size, overlap_size, max_tokens)
|
|
|
116 |
|
117 |
return {"results": results, "stats": stats}
|
118 |
|
119 |
+
|
120 |
# Gradio interface
|
121 |
iface = gr.Interface(
|
122 |
fn=upload_file,
|
123 |
inputs=[
|
124 |
gr.File(label="Upload File"),
|
125 |
+
gr.Textbox(label="Search Query"),
|
126 |
gr.Dropdown(choices=list(MODELS.keys()), label="Embedding Model"),
|
127 |
gr.Radio(choices=["sentence", "recursive"], label="Split Strategy"),
|
128 |
gr.Slider(100, 1000, step=100, value=500, label="Chunk Size"),
|
129 |
gr.Slider(0, 100, step=10, value=50, label="Overlap Size"),
|
130 |
gr.Slider(50, 500, step=50, value=200, label="Max Tokens"),
|
|
|
131 |
gr.Slider(1, 10, step=1, value=5, label="Top K")
|
132 |
],
|
133 |
outputs="json"
|