Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import os
|
|
5 |
import json
|
6 |
import io
|
7 |
import subprocess # To call process_hf_dataset.py
|
8 |
-
from database import init_chromadb,
|
9 |
|
10 |
# User-configurable variables
|
11 |
UPLOAD_DIR = "./uploads" # Directory for uploads
|
@@ -99,8 +99,23 @@ def index():
|
|
99 |
)
|
100 |
except subprocess.CalledProcessError as e:
|
101 |
return f"Error processing Hugging Face dataset: {e}", 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
elif 'reset_db' in request.form:
|
103 |
-
# Reset ChromaDB collection
|
104 |
try:
|
105 |
client = init_chromadb()
|
106 |
try:
|
@@ -108,7 +123,6 @@ def index():
|
|
108 |
except:
|
109 |
pass # Collection may not exist
|
110 |
client.create_collection(DB_NAME)
|
111 |
-
populate_sample_db(client) # Optionally repopulate with samples
|
112 |
return render_template(
|
113 |
'results_partial.html',
|
114 |
parts=None,
|
@@ -116,7 +130,7 @@ def index():
|
|
116 |
reconstructed_code=None,
|
117 |
code_input=None,
|
118 |
query_results=None,
|
119 |
-
message="Database reset
|
120 |
)
|
121 |
except Exception as e:
|
122 |
return f"Error resetting database: {e}", 500
|
@@ -134,14 +148,7 @@ def index():
|
|
134 |
)
|
135 |
return 'No file, code, or query provided', 400
|
136 |
|
137 |
-
# Initial page load
|
138 |
-
client = load_chromadb_from_hf()
|
139 |
-
# If no dataset exists locally, populate with samples
|
140 |
-
try:
|
141 |
-
if not client.list_collections()[0].name == DB_NAME:
|
142 |
-
populate_sample_db(client)
|
143 |
-
except:
|
144 |
-
populate_sample_db(client)
|
145 |
return render_template('index.html', parts=None, filename=None, reconstructed_code=None, code_input=None, query_results=None)
|
146 |
|
147 |
@app.route('/export_json', methods=['POST'])
|
|
|
5 |
import json
|
6 |
import io
|
7 |
import subprocess # To call process_hf_dataset.py
|
8 |
+
from database import init_chromadb, store_program, query_programs, load_chromadb_from_hf, DB_NAME
|
9 |
|
10 |
# User-configurable variables
|
11 |
UPLOAD_DIR = "./uploads" # Directory for uploads
|
|
|
99 |
)
|
100 |
except subprocess.CalledProcessError as e:
|
101 |
return f"Error processing Hugging Face dataset: {e}", 500
|
102 |
+
elif 'load_dataset' in request.form:
|
103 |
+
# Trigger loading of Hugging Face dataset without resetting
|
104 |
+
try:
|
105 |
+
subprocess.run(['python', 'process_hf_dataset.py'], check=True)
|
106 |
+
return render_template(
|
107 |
+
'results_partial.html',
|
108 |
+
parts=None,
|
109 |
+
filename="Hugging Face Dataset Loaded",
|
110 |
+
reconstructed_code=None,
|
111 |
+
code_input=None,
|
112 |
+
query_results=None,
|
113 |
+
message="Hugging Face dataset loaded and stored successfully."
|
114 |
+
)
|
115 |
+
except subprocess.CalledProcessError as e:
|
116 |
+
return f"Error loading Hugging Face dataset: {e}", 500
|
117 |
elif 'reset_db' in request.form:
|
118 |
+
# Reset ChromaDB collection (no repopulation with samples)
|
119 |
try:
|
120 |
client = init_chromadb()
|
121 |
try:
|
|
|
123 |
except:
|
124 |
pass # Collection may not exist
|
125 |
client.create_collection(DB_NAME)
|
|
|
126 |
return render_template(
|
127 |
'results_partial.html',
|
128 |
parts=None,
|
|
|
130 |
reconstructed_code=None,
|
131 |
code_input=None,
|
132 |
query_results=None,
|
133 |
+
message="Database reset successfully."
|
134 |
)
|
135 |
except Exception as e:
|
136 |
return f"Error resetting database: {e}", 500
|
|
|
148 |
)
|
149 |
return 'No file, code, or query provided', 400
|
150 |
|
151 |
+
# Initial page load (do not populate with samples automatically)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
return render_template('index.html', parts=None, filename=None, reconstructed_code=None, code_input=None, query_results=None)
|
153 |
|
154 |
@app.route('/export_json', methods=['POST'])
|