Spaces:
Running
Running
Update app.py
Browse files7 unmodified lines89101112131415161718193 unmodified lines23242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291 unmodified line1311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781797 unmodified linesversion="3.0.0")# Cloud Storage Dataset Connection PathDATA_URL = "hf://datasets/coderpetro/my-fast-data/data.parquet"# ==========================================# HOME ROUTE: BEAUTIFUL WEB USER INTERFACE (HTML/CSS)# ==========================================@app.get("/", response_class=HTMLResponse, include_in_schema=False)def web_ui():html_content = """3 unmodified lines<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Telegram Intelligence Matrix</title><link href="https://googleapis.com" rel="stylesheet"><style>* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', sans-serif; }body { background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); color: #f8fafc; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; }.container { background: rgba(30, 41, 59, 0.7); backdrop-filter: blur(16px); border: 1px solid rgba(255,255,255,0.1); border-radius: 24px; padding: 40px; width: 100%; max-width: 650px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); text-align: center; }h1 { font-size: 2.5rem; font-weight: 700; margin-bottom: 8px; background: linear-gradient(to right, #38bdf8, #818cf8); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }.subtitle { color: #94a3b8; font-size: 0.95rem; margin-bottom: 35px; }.tabs { display: flex; gap: 10px; margin-bottom: 25px; background: rgba(15, 23, 42, 0.5); padding: 6px; border-radius: 12px; }.tab-btn { flex: 1; padding: 12px; border: none; border-radius: 8px; background: transparent; color: #94a3b8; font-weight: 600; cursor: pointer; transition: all 0.3s ease; }.tab-btn.active { background: #38bdf8; color: #0f172a; box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3); }.input-group { position: relative; margin-bottom: 20px; }input { width: 100%; padding: 16px 20px; background: #0f172a; border: 2px solid rgba(255,255,255,0.05); border-radius: 14px; color: #fff; font-size: 1.1rem; transition: all 0.3s ease; outline: none; }input:focus { border-color: #38bdf8; box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.15); }.search-btn { width: 100%; padding: 16px; background: linear-gradient(to right, #38bdf8, #6366f1); color: #fff; border: none; border-radius: 14px; font-size: 1.1rem; font-weight: 600; cursor: pointer; transition: all 0.3s ease; box-shadow: 0 10px 20px -10px rgba(99, 102, 241, 0.5); }.search-btn:hover { transform: translateY(-2px); box-shadow: 0 15px 25px -10px rgba(99, 102, 241, 0.6); }.result-box { margin-top: 30px; display: none; text-align: left; background: rgba(15, 23, 42, 0.6); border-radius: 16px; padding: 25px; border: 1px solid rgba(255,255,255,0.05); }.result-row { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 1rem; }.result-row:last-child { border: none; }.label { color: #94a3b8; font-weight: 500; }.value { color: #38bdf8; font-weight: 600; }.error { color: #f43f5e; text-align: center; margin-top: 15px; font-weight: 500; display: none; }.loader { width: 24px; height: 24px; border: 3px solid #94a3b8; border-bottom-color: transparent; border-radius: 50%; display: inline-block; box-sizing: border-box; animation: rotation 1s linear infinite; display: none; margin-top: 15px; }@keyframes rotation { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }footer { margin-top: 40px; color: #64748b; font-size: 0.85rem; font-weight: 500; }</style></head><body><div class="container"><h1>Intelligence Matrix</h1><div class="subtitle">Secure high-speed query routing system by coderpetro</div><div class="tabs"><button class="tab-btn active" onclick="switchTab('tg', event)">TG to Number</button><button class="tab-btn" onclick="switchTab('num', event)">Number to TG</button></div><div class="input-group"><input type="text" id="searchInput" placeholder="Enter Numeric Telegram ID..."></div><button class="search-btn" onclick="executeSearch()">Search Repository</button><div id="loader" class="loader"></div><div id="errorBox" class="error"></div><div id="resultBox" class="result-box"><div class="result-row"><span class="label">Telegram ID:</span><span class="value" id="resId">-</span></div><div class="result-row"><span class="label">Phone Number:</span><span class="value" id="resNum">-</span></div><div class="result-row"><span class="label">Country:</span><span class="value" id="resCountry">-</span></div><div class="result-row"><span class="label">Developer:</span><span class="value" id="resDev">-</span></div></div></div><footer>Designed & Developed by coderpetro © 2026</footer><script>let currentMode = 'tg';function switchTab(mode, event) {currentMode = mode;document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));event.target.classList.add('active');document.getElementById('searchInput').placeholder = mode === 'tg' ? 'Enter Numeric Telegram ID...' : 'Enter Phone Number (e.g. 9198765...)';document.getElementById('resultBox').style.display = 'none';document.getElementById('errorBox').style.display = 'none';}async function executeSearch() {const queryVal = document.getElementById('searchInput').value.trim();const loader = document.getElementById('loader');const errorBox = document.getElementById('errorBox');const resultBox = document.getElementById('resultBox');if (!queryVal) return;loader.style.display = 'inline-block';errorBox.style.display = 'none';resultBox.style.display = 'none';let endpoint = currentMode === 'tg' ? `/tg-to-num?tg_id=${queryVal}` : `/num-to-tg?phone=${encodeURIComponent(queryVal)}`;try {const response = await fetch(endpoint);const data = await response.json();loader.style.display = 'none';if (response.status === 200 && !data.status) {document.getElementById('resId').innerText = data.id;document.getElementById('resNum').innerText = data.number;document.getElementById('resCountry').innerText = data.country;document.getElementById('resDev').innerText = data.developer;resultBox.style.display = 'block';} else {errorBox.innerText = data.detail || data.message || "No records tracking this parameter.";errorBox.style.display = 'block';}} catch (err) {loader.style.display = 'none';errorBox.innerText = "Mainframe gateway connection failure.";errorBox.style.display = 'block';}}</script></body>1 unmodified line"""return html_content# ==========================================# ROUTE 2: TELEGRAM ID TO PHONE NUMBER (TG TO NUM)# ==========================================@app.get("/tg-to-num", summary="Query phone records using numeric Telegram ID")def telegram_to_number(tg_id: str = Query(..., description="The target numeric Telegram ID to look up")):if not tg_id.isdigit():raise HTTPException(status_code=400, detail="Query validation error: Telegram ID must be completely numeric.")try:con = duckdb.connect()sql_query = f"""SELECT "Номер телефона"FROM '{DATA_URL}'WHERE "Telegram ID" = '{tg_id}'LIMIT 1"""db_result = con.execute(sql_query).fetchall()if db_result and len(db_result) > 0:raw_phone = str(db_result[0][0]).strip()clean_phone = raw_phone.replace("+", "").strip()country_code = clean_phone[:2] if len(clean_phone) > 5 else "Unknown"return {"telegram id": f"telegram id ; {tg_id}","id": tg_id,"number": raw_phone,"country": f"+{country_code}","developer": "coderpetro"}else:return {"status": 404,"id": tg_id,"message": "No matching log records found in database matrix."}except Exception as e:raise HTTPException(status_code=500, detail=str(e))# ==========================================# ROUTE 3: PHONE NUMBER TO TELEGRAM ID (NUM TO TG)# ==========================================@app.get("/num-to-tg", summary="Query Telegram ID using Phone Number")def number_to_telegram(7 unmodified lines891011121314153 unmodified lines19202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879801 unmodified line8283848586878889909192939495969798991001011021031041051061071081091101111121131147 unmodified linesversion="3.0.0")DATA_URL = "hf://datasets/coderpetro/my-fast-data/data.parquet"@app.get("/", response_class=HTMLResponse, include_in_schema=False)def web_ui():html_content = """3 unmodified lines<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Telegram Intelligence Matrix</title><link href="https://jsdelivr.net" rel="stylesheet"><style>body { background: #0f172a; color: #f8fafc; min-height: 100vh; display: flex; align-items: center; justify-content: center; }.card { background: #1e293b; border: 1px solid rgba(255,255,255,0.1); border-radius: 16px; width: 100%; max-width: 550px; padding: 30px; box-shadow: 0 20px 40px rgba(0,0,0,0.5); }.nav-link { color: #94a3b8; cursor: pointer; font-weight: 600; }.nav-link.active { color: #38bdf8 !important; background: transparent !important; border-bottom: 2px solid #38bdf8; }input { background: #0f172a !important; color: #fff !important; border: 1px solid rgba(255,255,255,0.1) !important; padding: 12px !important; border-radius: 8px !important; }.btn-search { background: linear-gradient(to right, #38bdf8, #6366f1); color: #fff; font-weight: 600; border: none; padding: 12px; border-radius: 8px; width: 100%; }.res-box { background: #0f172a; border-radius: 8px; padding: 15px; margin-top: 20px; display: none; border: 1px solid rgba(255,255,255,0.05); }</style></head><body><div class="card"><h2 class="text-center mb-1" style="color: #38bdf8;">Intelligence Matrix</h2><p class="text-center text-muted small mb-4">Cloud Data Engine by coderpetro</p><ul class="nav nav-tabs nav-fill mb-4"><li class="nav-item"><a class="nav-link active" id="tgTab" onclick="setMode('tg')">TG to Number</a></li><li class="nav-item"><a class="nav-link" id="numTab" onclick="setMode('num')">Number to TG</a></li></ul><div class="mb-3"><input type="text" id="inp" class="form-control" placeholder="Enter Numeric Telegram ID..."></div><button class="btn-search" onclick="doSearch()">Search Repository</button><div id="ld" class="text-center text-muted small mt-3" style="display:none;">Searching global matrix...</div><div id="box" class="res-box"><div class="d-flex justify-content-between py-1"><span>ID:</span><span id="rId" style="color:#38bdf8;">-</span></div><div class="d-flex justify-content-between py-1"><span>Number:</span><span id="rNum" style="color:#38bdf8;">-</span></div><div class="d-flex justify-content-between py-1"><span>Country:</span><span id="rC" style="color:#38bdf8;">-</span></div><div class="d-flex justify-content-between py-1"><span>Developer:</span><span id="rD" style="color:#38bdf8;">-</span></div></div></div><script>let mode = 'tg';function setMode(m) {mode = m;document.getElementById('tgTab').classList.toggle('active', m=='tg');document.getElementById('numTab').classList.toggle('active', m=='num');document.getElementById('inp').placeholder = m=='tg' ? 'Enter Numeric Telegram ID...' : 'Enter Phone Number...';document.getElementById('box').style.display = 'none';}async function doSearch() {let val = document.getElementById('inp').value.strip();if(!val) return;document.getElementById('ld').style.display = 'block';document.getElementById('box').style.display = 'none';let url = mode == 'tg' ? `/tg-to-num?tg_id=${val}` : `/num-to-tg?phone=${encodeURIComponent(val)}`;try {let r = await fetch(url);let d = await r.json();document.getElementById('ld').style.display = 'none';if(r.status == 200 && !d.status) {document.getElementById('rId').innerText = d.id;document.getElementById('rNum').innerText = d.number;document.getElementById('rC').innerText = d.country;document.getElementById('rD').innerText = d.developer;document.getElementById('box').style.display = 'block';} else { alert(d.message || "Record not tracking."); }} catch(e) { document.getElementById('ld').style.display = 'none'; alert("Gateway Failure."); }}</script></body>1 unmodified line"""return html_content@app.get("/tg-to-num")def telegram_to_number(tg_id: str = Query(..., description="Telegram ID")):if not tg_id.isdigit():raise HTTPException(status_code=400, detail="Must be numeric.")try:con = duckdb.connect()res = con.execute(f'SELECT "Номер телефона" FROM "{DATA_URL}" WHERE "Telegram ID" = \'{tg_id}\' LIMIT 1').fetchall()if res and len(res) > 0:p = str(res[0][0]).strip()c = p.replace("+", "").strip()[:2] if len(p) > 5 else "Unknown"return {"telegram id": f"telegram id ; {tg_id}", "id": tg_id, "number": p, "country": f"+{c}", "developer": "coderpetro"}return {"status": 404, "id": tg_id, "message": "Not found."}except Exception as e:raise HTTPException(status_code=500, detail=str(e))@app.get("/num-to-tg")def number_to_telegram(phone: str = Query(..., description="Phone Number")):p1 = phone.strip()p2 = f"+{p1}" if not p1.startswith("+") else p1.replace("+", "")try:con = duckdb.connect()res = con.execute(f'SELECT "Telegram ID" FROM "{DATA_URL}" WHERE "Номер телефона" = \'{p1}\' OR "Номер телефона" = \'{p2}\' LIMIT 1').fetchall()if res and len(res) > 0:tid = str(res[0][0]).strip()num = p1 if p1.startswith("+") else f"+{p1}"c = num.replace("+", "").strip()[:2] if len(num) > 5 else "Unknown"return {"telegram id": f"telegram id ; {tid}", "id": tid, "number": num, "country": f"+{c}", "developer": "coderpetro"}return {"status": 404, "number": phone, "message": "Not found."}except Exception as e:raise HTTPException(status_code=500, detail=str(e))
app.py+71-136