Tuana commited on
Commit
a8ac0f0
·
verified ·
1 Parent(s): d801a52

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -58,12 +58,16 @@ Open the printed URL (default **http://127.0.0.1:7861** if the port is free). Us
58
  Push the contents of this folder as the Space root, not the whole training repo:
59
 
60
  ```bash
61
- cd sql_compare_ui_qwen
62
- uv run hf repo create Tuana/qwen-text2sql-demo --type space --sdk gradio
63
- uv run hf upload Tuana/qwen-text2sql-demo . . \
 
 
 
64
  --repo-type space \
65
  --exclude ".env" \
66
- --exclude "__pycache__/*" \
 
67
  --exclude "local_inference.py" \
68
  --exclude "inference_device.py"
69
  ```
 
58
  Push the contents of this folder as the Space root, not the whole training repo:
59
 
60
  ```bash
61
+ uv run hf repo create Tuana/qwen-text2sql-demo \
62
+ --type space \
63
+ --space-sdk gradio \
64
+ --exist-ok
65
+
66
+ uv run hf upload Tuana/qwen-text2sql-demo sql_compare_ui_qwen . \
67
  --repo-type space \
68
  --exclude ".env" \
69
+ --exclude "data/spider_eval_synthetic/synthetic.db" \
70
+ --exclude "**/__pycache__/**" \
71
  --exclude "local_inference.py" \
72
  --exclude "inference_device.py"
73
  ```
__pycache__/__init__.cpython-311.pyc ADDED
Binary file (292 Bytes). View file
 
__pycache__/__init__.cpython-312.pyc ADDED
Binary file (281 Bytes). View file
 
__pycache__/app.cpython-311.pyc ADDED
Binary file (44.9 kB). View file
 
__pycache__/app.cpython-312.pyc ADDED
Binary file (21.7 kB). View file
 
__pycache__/inference_device.cpython-311.pyc ADDED
Binary file (5.64 kB). View file
 
__pycache__/inference_device.cpython-312.pyc ADDED
Binary file (5.57 kB). View file
 
__pycache__/local_inference.cpython-311.pyc ADDED
Binary file (9.77 kB). View file
 
__pycache__/prompting.cpython-311.pyc ADDED
Binary file (1.77 kB). View file
 
app.py CHANGED
@@ -390,8 +390,69 @@ def _compare_sqlite_db_path() -> Path:
390
  return Path(raw).expanduser().resolve()
391
 
392
 
393
- def _database_preview_rows(limit: int = 5) -> list[dict[str, str]]:
 
 
 
 
 
 
 
 
 
 
394
  db = _compare_sqlite_db_path()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
  if db.is_file():
396
  conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)
397
  conn.row_factory = sqlite3.Row
@@ -418,12 +479,9 @@ def _database_preview_rows(limit: int = 5) -> list[dict[str, str]]:
418
  conn.close()
419
 
420
  data_dir = _demo_data_dir()
421
- with (data_dir / "department.csv").open(newline="", encoding="utf-8") as f:
422
- departments = {r["department_id"]: r for r in csv.DictReader(f)}
423
- with (data_dir / "head.csv").open(newline="", encoding="utf-8") as f:
424
- heads = {r["head_id"]: r for r in csv.DictReader(f)}
425
- with (data_dir / "management.csv").open(newline="", encoding="utf-8") as f:
426
- management = list(csv.DictReader(f))
427
 
428
  preview: list[dict[str, str]] = []
429
  for rel in management:
@@ -563,9 +621,7 @@ def _execute_compare_sql(sql: str, *, row_limit: int = 150) -> str:
563
  ok, stmt = _compare_validate_select(sql)
564
  if not ok:
565
  return f"Error: {stmt}"
566
- db = _compare_sqlite_db_path()
567
- if not db.is_file():
568
- return f"Error: database file not found: {db}"
569
  try:
570
  conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)
571
  conn.row_factory = sqlite3.Row
 
390
  return Path(raw).expanduser().resolve()
391
 
392
 
393
+ def _load_csv_rows(data_dir: Path) -> tuple[list[dict[str, str]], list[dict[str, str]], list[dict[str, str]]]:
394
+ with (data_dir / "department.csv").open(newline="", encoding="utf-8") as f:
395
+ departments = list(csv.DictReader(f))
396
+ with (data_dir / "head.csv").open(newline="", encoding="utf-8") as f:
397
+ heads = list(csv.DictReader(f))
398
+ with (data_dir / "management.csv").open(newline="", encoding="utf-8") as f:
399
+ management = list(csv.DictReader(f))
400
+ return departments, heads, management
401
+
402
+
403
+ def _ensure_compare_sqlite_db() -> Path:
404
  db = _compare_sqlite_db_path()
405
+ if db.is_file():
406
+ return db
407
+
408
+ data_dir = _demo_data_dir()
409
+ departments, heads, management = _load_csv_rows(data_dir)
410
+ db.parent.mkdir(parents=True, exist_ok=True)
411
+ conn = sqlite3.connect(db)
412
+ try:
413
+ conn.executescript(
414
+ """
415
+ DROP TABLE IF EXISTS department;
416
+ DROP TABLE IF EXISTS management;
417
+ DROP TABLE IF EXISTS head;
418
+
419
+ CREATE TABLE department (
420
+ department_id VARCHAR,
421
+ name VARCHAR,
422
+ creation VARCHAR
423
+ );
424
+ CREATE TABLE management (
425
+ department_id VARCHAR,
426
+ head_id VARCHAR,
427
+ temporary_acting VARCHAR
428
+ );
429
+ CREATE TABLE head (
430
+ head_id VARCHAR,
431
+ name VARCHAR,
432
+ born_state VARCHAR
433
+ );
434
+ """
435
+ )
436
+ conn.executemany(
437
+ "INSERT INTO department (department_id, name, creation) VALUES (?, ?, ?)",
438
+ [(r["department_id"], r["name"], r["creation"]) for r in departments],
439
+ )
440
+ conn.executemany(
441
+ "INSERT INTO head (head_id, name, born_state) VALUES (?, ?, ?)",
442
+ [(r["head_id"], r["name"], r["born_state"]) for r in heads],
443
+ )
444
+ conn.executemany(
445
+ "INSERT INTO management (department_id, head_id, temporary_acting) VALUES (?, ?, ?)",
446
+ [(r["department_id"], r["head_id"], r["temporary_acting"]) for r in management],
447
+ )
448
+ conn.commit()
449
+ finally:
450
+ conn.close()
451
+ return db
452
+
453
+
454
+ def _database_preview_rows(limit: int = 5) -> list[dict[str, str]]:
455
+ db = _ensure_compare_sqlite_db()
456
  if db.is_file():
457
  conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)
458
  conn.row_factory = sqlite3.Row
 
479
  conn.close()
480
 
481
  data_dir = _demo_data_dir()
482
+ dept_rows, head_rows, management = _load_csv_rows(data_dir)
483
+ departments = {r["department_id"]: r for r in dept_rows}
484
+ heads = {r["head_id"]: r for r in head_rows}
 
 
 
485
 
486
  preview: list[dict[str, str]] = []
487
  for rel in management:
 
621
  ok, stmt = _compare_validate_select(sql)
622
  if not ok:
623
  return f"Error: {stmt}"
624
+ db = _ensure_compare_sqlite_db()
 
 
625
  try:
626
  conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)
627
  conn.row_factory = sqlite3.Row