Spaces:
Sleeping
Sleeping
Commit Β·
e667fbe
1
Parent(s): 603b606
defrg
Browse files
app.py
CHANGED
|
@@ -14,17 +14,38 @@ import json
|
|
| 14 |
import subprocess
|
| 15 |
import base64
|
| 16 |
import io
|
|
|
|
| 17 |
from pathlib import Path
|
| 18 |
from typing import Iterator
|
| 19 |
|
| 20 |
# ==========================================
|
| 21 |
-
# RELATIVE PATH RESOLUTION
|
| 22 |
# ==========================================
|
| 23 |
try:
|
| 24 |
PROJECT_ROOT = Path(__file__).resolve().parent
|
| 25 |
except NameError:
|
| 26 |
PROJECT_ROOT = Path(".").resolve()
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
if (PROJECT_ROOT / "data" / "database").exists():
|
| 29 |
DB_ROOT = PROJECT_ROOT / "data" / "database"
|
| 30 |
else:
|
|
@@ -170,7 +191,7 @@ def run_query(method, sample_q, custom_q, db_id):
|
|
| 170 |
if quant_engine is None:
|
| 171 |
return "-- β ENGINE CRASH", pd.DataFrame(columns=["Error"]), "Failed to load model. Did you move the tokenizer files and add config.json to int8_dynamic/?"
|
| 172 |
except Exception as e:
|
| 173 |
-
return f"-- β ENGINE CRASH\n-- {str(e)}", pd.DataFrame(columns=["Error Status"]), f"Critical failure loading model: {e}"
|
| 174 |
|
| 175 |
def _log(error_type: str, *, question: str, db_id_val: str, sql: str = "", error_msg: str = "") -> None:
|
| 176 |
_QUERY_LOG.append({"t": time.time(), "db_id": str(db_id_val), "question": str(question), "sql": str(sql), "error_type": str(error_type), "error_msg": str(error_msg)})
|
|
@@ -566,5 +587,4 @@ if __name__ == "__main__":
|
|
| 566 |
# If it's a different OSError, raise it normally
|
| 567 |
raise e
|
| 568 |
else:
|
| 569 |
-
print(f"β Could not find an open port between {base_port} and {base_port + max_retries - 1}.")
|
| 570 |
-
|
|
|
|
| 14 |
import subprocess
|
| 15 |
import base64
|
| 16 |
import io
|
| 17 |
+
import zipfile
|
| 18 |
from pathlib import Path
|
| 19 |
from typing import Iterator
|
| 20 |
|
| 21 |
# ==========================================
|
| 22 |
+
# RELATIVE PATH RESOLUTION & ZIP EXTRACTION
|
| 23 |
# ==========================================
|
| 24 |
try:
|
| 25 |
PROJECT_ROOT = Path(__file__).resolve().parent
|
| 26 |
except NameError:
|
| 27 |
PROJECT_ROOT = Path(".").resolve()
|
| 28 |
|
| 29 |
+
def extract_if_needed(folder_name: str, zip_name: str):
|
| 30 |
+
"""Checks if a folder exists; if not, looks for a zip and extracts it."""
|
| 31 |
+
target_dir = PROJECT_ROOT / folder_name
|
| 32 |
+
zip_path = PROJECT_ROOT / zip_name
|
| 33 |
+
|
| 34 |
+
# If folder doesn't exist, or it exists but is empty
|
| 35 |
+
if not target_dir.exists() or not any(target_dir.iterdir()):
|
| 36 |
+
if zip_path.exists():
|
| 37 |
+
print(f"π¦ Extracting {zip_name} to {folder_name}...", flush=True)
|
| 38 |
+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
| 39 |
+
zip_ref.extractall(PROJECT_ROOT)
|
| 40 |
+
print(f"β
{zip_name} extracted successfully.", flush=True)
|
| 41 |
+
else:
|
| 42 |
+
print(f"β οΈ Warning: Neither {folder_name}/ nor {zip_name} found in {PROJECT_ROOT}!", flush=True)
|
| 43 |
+
|
| 44 |
+
# π¨ RUN EXTRACTION BEFORE ANYTHING ELSE BOOTS UP π¨
|
| 45 |
+
extract_if_needed("final_databases", "final_databases.zip")
|
| 46 |
+
extract_if_needed("int8_dynamic", "int8_dynamic.zip")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
if (PROJECT_ROOT / "data" / "database").exists():
|
| 50 |
DB_ROOT = PROJECT_ROOT / "data" / "database"
|
| 51 |
else:
|
|
|
|
| 191 |
if quant_engine is None:
|
| 192 |
return "-- β ENGINE CRASH", pd.DataFrame(columns=["Error"]), "Failed to load model. Did you move the tokenizer files and add config.json to int8_dynamic/?"
|
| 193 |
except Exception as e:
|
| 194 |
+
return f"-- β ENGINE CRASH\n-- {str(e)}", pd.DataFrame(columns=["Error Status"]), f"Critical failure loading model: {e}\nDid the zip file extract properly?"
|
| 195 |
|
| 196 |
def _log(error_type: str, *, question: str, db_id_val: str, sql: str = "", error_msg: str = "") -> None:
|
| 197 |
_QUERY_LOG.append({"t": time.time(), "db_id": str(db_id_val), "question": str(question), "sql": str(sql), "error_type": str(error_type), "error_msg": str(error_msg)})
|
|
|
|
| 587 |
# If it's a different OSError, raise it normally
|
| 588 |
raise e
|
| 589 |
else:
|
| 590 |
+
print(f"β Could not find an open port between {base_port} and {base_port + max_retries - 1}.")
|
|
|