Watchhrr commited on
Commit
d5f85e0
·
verified ·
1 Parent(s): 610797f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -47
app.py CHANGED
@@ -1,55 +1,47 @@
1
- import streamlit as st
2
  import sqlite3
3
  import os
4
  from huggingface_hub import hf_hub_download
5
 
6
- # Page Config
7
- st.set_page_config(page_title="Hitech Telegram Search", page_icon="🔍")
8
 
9
- st.title("🚀 Hitech Telegram Search API")
10
- st.markdown("### 72.6 Million Unique Records Database")
11
-
12
- # --- DATABASE SETUP ---
13
  REPO_ID = "Watchhrr/Telegram"
14
  DB_FILE = "Telegram_part_1_DB.db"
15
 
16
- @st.cache_resource
17
- def load_database():
18
- try:
19
- # Downloading DB from Hugging Face
20
- db_path = hf_hub_download(repo_id=REPO_ID, filename=DB_FILE, repo_type="dataset")
21
- return db_path
22
- except Exception as e:
23
- st.error(f"Error loading database: {e}")
24
- return None
25
-
26
- db_path = load_database()
27
-
28
- # --- SEARCH UI ---
29
- query = st.text_input("Enter Phone Number or User ID:", placeholder="e.g. 919876543210 or 12345678")
30
-
31
- if st.button("Search"):
32
- if query and db_path:
33
- clean_q = ''.join(filter(str.isdigit, str(query)))
34
-
35
- conn = sqlite3.connect(db_path)
36
- conn.row_factory = sqlite3.Row
37
- cursor = conn.cursor()
38
-
39
- # Optimized Search
40
- sql = "SELECT * FROM users WHERE user_id = ? OR phone = ? LIMIT 20"
41
- cursor.execute(sql, (query, clean_q))
42
- rows = cursor.fetchall()
43
- conn.close()
44
-
45
- if rows:
46
- st.success(f"Found {len(rows)} result(s)!")
47
- for row in rows:
48
- st.json(dict(row)) # API jaisa JSON format mein result dikhayega
49
- else:
50
- st.warning("No records found in the database.")
51
- else:
52
- st.info("Please enter a search term.")
53
-
54
- st.divider()
55
- st.caption("Powered by Midnight Syndicate | 72M Unique Records")
 
1
+ from fastapi import FastAPI, Query
2
  import sqlite3
3
  import os
4
  from huggingface_hub import hf_hub_download
5
 
6
+ app = FastAPI(title="Hitech OSINT API")
 
7
 
8
+ # --- CONFIG ---
 
 
 
9
  REPO_ID = "Watchhrr/Telegram"
10
  DB_FILE = "Telegram_part_1_DB.db"
11
 
12
+ # Database download on startup
13
+ DB_PATH = hf_hub_download(repo_id=REPO_ID, filename=DB_FILE, repo_type="dataset")
14
+
15
+ @app.get("/search")
16
+ def hitech_search(q: str = Query(None, description="Phone number or User ID")):
17
+ if not q:
18
+ return {"status": "error", "message": "Query parameter 'q' is missing. Use /search?q=YOUR_QUERY"}
19
+
20
+ # Cleaning input
21
+ clean_q = ''.join(filter(str.isdigit, str(q)))
22
+
23
+ conn = sqlite3.connect(DB_PATH)
24
+ conn.row_factory = sqlite3.Row # Dictionary format
25
+ cursor = conn.cursor()
26
+
27
+ # Optimized Query
28
+ sql = "SELECT * FROM users WHERE user_id = ? OR phone = ? LIMIT 50"
29
+ cursor.execute(sql, (q, clean_q))
30
+
31
+ results = [dict(row) for row in cursor.fetchall()]
32
+ conn.close()
33
+
34
+ if not results:
35
+ return {"status": "success", "count": 0, "data": [], "msg": "No records found."}
36
+
37
+ return {
38
+ "status": "success",
39
+ "total_results": len(results),
40
+ "data": results,
41
+ "provider": "Midnight Syndicate"
42
+ }
43
+
44
+ @app.get("/")
45
+ def home():
46
+ return {"status": "online", "endpoint": "/search?q={id_or_phone}"}
47
+