Update app.py
Browse files
app.py
CHANGED
|
@@ -4,11 +4,10 @@ import pandas as pd
|
|
| 4 |
import os
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
-
# Fast download enable
|
| 8 |
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
|
| 9 |
|
| 10 |
# --- CONFIGURATION ---
|
| 11 |
-
# Token ko Space Settings > Secrets mein HF_TOKEN naam se save karna
|
| 12 |
TOKEN = os.getenv("HF_TOKEN")
|
| 13 |
REPO = "Watchhrr/Telegram"
|
| 14 |
DB1_NAME = "Telegram_Master_DB.db"
|
|
@@ -17,11 +16,11 @@ DB2_NAME = "Telegram_Part2.db"
|
|
| 17 |
# --- DOWNLOAD DATABASES ---
|
| 18 |
def load_data():
|
| 19 |
if not TOKEN:
|
|
|
|
| 20 |
return None, None
|
| 21 |
|
| 22 |
print("β³ Downloading Databases (Large Files)...")
|
| 23 |
try:
|
| 24 |
-
# Dono DB files ko download karke local path lena
|
| 25 |
path1 = hf_hub_download(repo_id=REPO, filename=DB1_NAME, repo_type="dataset", token=TOKEN)
|
| 26 |
path2 = hf_hub_download(repo_id=REPO, filename=DB2_NAME, repo_type="dataset", token=TOKEN)
|
| 27 |
return path1, path2
|
|
@@ -29,7 +28,6 @@ def load_data():
|
|
| 29 |
print(f"Download Error: {e}")
|
| 30 |
return None, None
|
| 31 |
|
| 32 |
-
# Initialize paths at startup
|
| 33 |
db1_path, db2_path = load_data()
|
| 34 |
|
| 35 |
def hitech_search(search_query):
|
|
@@ -40,15 +38,11 @@ def hitech_search(search_query):
|
|
| 40 |
return "β οΈ Please enter at least 3 characters."
|
| 41 |
|
| 42 |
try:
|
| 43 |
-
# SQLite Connection
|
| 44 |
conn = sqlite3.connect(db1_path)
|
| 45 |
-
# Dusre DB ko attach karna taaki ek sath search ho sake
|
| 46 |
conn.execute(f"ATTACH DATABASE '{db2_path}' AS db2")
|
| 47 |
|
| 48 |
-
# Phone search ke liye sirf numbers extract karna
|
| 49 |
clean_phone = ''.join(filter(str.isdigit, str(search_query)))
|
| 50 |
|
| 51 |
-
# Optimized SQL Query with UNION
|
| 52 |
sql = """
|
| 53 |
SELECT 'Master' as source, user_id, phone, username, first_name, last_name FROM users
|
| 54 |
WHERE phone = ? OR user_id = ? OR username = ?
|
|
@@ -70,9 +64,9 @@ def hitech_search(search_query):
|
|
| 70 |
return f"β Search Error: {str(e)}"
|
| 71 |
|
| 72 |
# --- GRADIO UI ---
|
| 73 |
-
with gr.Blocks(
|
| 74 |
gr.Markdown("# π Hitech Telegram Search Engine")
|
| 75 |
-
gr.Markdown("Searching across **251 Million+** records
|
| 76 |
|
| 77 |
with gr.Row():
|
| 78 |
input_text = gr.Textbox(
|
|
@@ -84,9 +78,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 84 |
search_btn = gr.Button("π Deep Search", variant="primary")
|
| 85 |
output_table = gr.DataFrame(label="Results")
|
| 86 |
|
| 87 |
-
# Click aur Enter dono pe kaam karega
|
| 88 |
search_btn.click(fn=hitech_search, inputs=input_text, outputs=output_table)
|
| 89 |
input_text.submit(fn=hitech_search, inputs=input_text, outputs=output_table)
|
| 90 |
|
|
|
|
| 91 |
if __name__ == "__main__":
|
| 92 |
-
|
|
|
|
| 4 |
import os
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
+
# Fast download enable
|
| 8 |
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
|
| 9 |
|
| 10 |
# --- CONFIGURATION ---
|
|
|
|
| 11 |
TOKEN = os.getenv("HF_TOKEN")
|
| 12 |
REPO = "Watchhrr/Telegram"
|
| 13 |
DB1_NAME = "Telegram_Master_DB.db"
|
|
|
|
| 16 |
# --- DOWNLOAD DATABASES ---
|
| 17 |
def load_data():
|
| 18 |
if not TOKEN:
|
| 19 |
+
print("β HF_TOKEN not found in Secrets!")
|
| 20 |
return None, None
|
| 21 |
|
| 22 |
print("β³ Downloading Databases (Large Files)...")
|
| 23 |
try:
|
|
|
|
| 24 |
path1 = hf_hub_download(repo_id=REPO, filename=DB1_NAME, repo_type="dataset", token=TOKEN)
|
| 25 |
path2 = hf_hub_download(repo_id=REPO, filename=DB2_NAME, repo_type="dataset", token=TOKEN)
|
| 26 |
return path1, path2
|
|
|
|
| 28 |
print(f"Download Error: {e}")
|
| 29 |
return None, None
|
| 30 |
|
|
|
|
| 31 |
db1_path, db2_path = load_data()
|
| 32 |
|
| 33 |
def hitech_search(search_query):
|
|
|
|
| 38 |
return "β οΈ Please enter at least 3 characters."
|
| 39 |
|
| 40 |
try:
|
|
|
|
| 41 |
conn = sqlite3.connect(db1_path)
|
|
|
|
| 42 |
conn.execute(f"ATTACH DATABASE '{db2_path}' AS db2")
|
| 43 |
|
|
|
|
| 44 |
clean_phone = ''.join(filter(str.isdigit, str(search_query)))
|
| 45 |
|
|
|
|
| 46 |
sql = """
|
| 47 |
SELECT 'Master' as source, user_id, phone, username, first_name, last_name FROM users
|
| 48 |
WHERE phone = ? OR user_id = ? OR username = ?
|
|
|
|
| 64 |
return f"β Search Error: {str(e)}"
|
| 65 |
|
| 66 |
# --- GRADIO UI ---
|
| 67 |
+
with gr.Blocks() as app: # Yahan 'demo' ki jagah 'app' kar diya
|
| 68 |
gr.Markdown("# π Hitech Telegram Search Engine")
|
| 69 |
+
gr.Markdown("Searching across **251 Million+** records.")
|
| 70 |
|
| 71 |
with gr.Row():
|
| 72 |
input_text = gr.Textbox(
|
|
|
|
| 78 |
search_btn = gr.Button("π Deep Search", variant="primary")
|
| 79 |
output_table = gr.DataFrame(label="Results")
|
| 80 |
|
|
|
|
| 81 |
search_btn.click(fn=hitech_search, inputs=input_text, outputs=output_table)
|
| 82 |
input_text.submit(fn=hitech_search, inputs=input_text, outputs=output_table)
|
| 83 |
|
| 84 |
+
# Gradio 6.0 fix: theme yahan launch mein aayega
|
| 85 |
if __name__ == "__main__":
|
| 86 |
+
app.launch(theme=gr.themes.Soft())
|