Spaces:
Sleeping
Sleeping
Update code
Browse files- dashboard.py +44 -0
- requirements.txt +1 -0
dashboard.py
CHANGED
|
@@ -23,6 +23,47 @@ from flask import Flask, render_template, jsonify, request, Response
|
|
| 23 |
from typing import Optional
|
| 24 |
from collections import defaultdict
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# ==========================================
|
| 27 |
# AI CONFIGURATION
|
| 28 |
# Set via environment variables (e.g. in .env or hosting platform settings)
|
|
@@ -2067,6 +2108,9 @@ def main():
|
|
| 2067 |
|
| 2068 |
args = parser.parse_args()
|
| 2069 |
|
|
|
|
|
|
|
|
|
|
| 2070 |
global DB_PATH
|
| 2071 |
DB_PATH = args.db
|
| 2072 |
|
|
|
|
| 23 |
from typing import Optional
|
| 24 |
from collections import defaultdict
|
| 25 |
|
| 26 |
+
# ==========================================
|
| 27 |
+
# DATABASE DOWNLOAD FROM HF DATASET
|
| 28 |
+
# ==========================================
|
| 29 |
+
HF_DATASET_REPO = "rottg/telegram-db"
|
| 30 |
+
DB_FILENAME = "telegram.db"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def ensure_db_exists():
|
| 34 |
+
"""Download DB from HF Dataset repo if it doesn't exist locally."""
|
| 35 |
+
if os.path.exists(DB_FILENAME):
|
| 36 |
+
print(f"✓ Database found: {DB_FILENAME}")
|
| 37 |
+
return True
|
| 38 |
+
|
| 39 |
+
print(f"Database not found locally. Downloading from HF Dataset...")
|
| 40 |
+
try:
|
| 41 |
+
from huggingface_hub import hf_hub_download
|
| 42 |
+
|
| 43 |
+
# Get token from environment or file
|
| 44 |
+
token = os.environ.get("HF_TOKEN")
|
| 45 |
+
if not token:
|
| 46 |
+
token_file = os.path.join(os.path.dirname(__file__), ".hf_token")
|
| 47 |
+
if os.path.exists(token_file):
|
| 48 |
+
with open(token_file) as f:
|
| 49 |
+
token = f.read().strip()
|
| 50 |
+
|
| 51 |
+
# Download the DB file
|
| 52 |
+
local_path = hf_hub_download(
|
| 53 |
+
repo_id=HF_DATASET_REPO,
|
| 54 |
+
filename=DB_FILENAME,
|
| 55 |
+
repo_type="dataset",
|
| 56 |
+
token=token,
|
| 57 |
+
local_dir=".",
|
| 58 |
+
local_dir_use_symlinks=False
|
| 59 |
+
)
|
| 60 |
+
print(f"✓ Database downloaded: {local_path}")
|
| 61 |
+
return True
|
| 62 |
+
except Exception as e:
|
| 63 |
+
print(f"✗ Failed to download database: {e}")
|
| 64 |
+
print(" Make sure to upload telegram.db to the Dataset repo first.")
|
| 65 |
+
return False
|
| 66 |
+
|
| 67 |
# ==========================================
|
| 68 |
# AI CONFIGURATION
|
| 69 |
# Set via environment variables (e.g. in .env or hosting platform settings)
|
|
|
|
| 2108 |
|
| 2109 |
args = parser.parse_args()
|
| 2110 |
|
| 2111 |
+
# Download DB from HF Dataset if not present
|
| 2112 |
+
ensure_db_exists()
|
| 2113 |
+
|
| 2114 |
global DB_PATH
|
| 2115 |
DB_PATH = args.db
|
| 2116 |
|
requirements.txt
CHANGED
|
@@ -2,3 +2,4 @@ flask>=3.0
|
|
| 2 |
gunicorn>=21.2
|
| 3 |
requests>=2.31
|
| 4 |
ijson>=3.2
|
|
|
|
|
|
| 2 |
gunicorn>=21.2
|
| 3 |
requests>=2.31
|
| 4 |
ijson>=3.2
|
| 5 |
+
huggingface_hub>=0.20
|