Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,31 @@
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
import shutil
|
| 4 |
-
import logging
|
| 5 |
-
import requests
|
| 6 |
import pandas as pd
|
| 7 |
import gradio as gr
|
| 8 |
from selenium import webdriver
|
| 9 |
from selenium.webdriver.chrome.service import Service
|
| 10 |
from selenium.webdriver.chrome.options import Options
|
| 11 |
-
from fake_useragent import UserAgent
|
| 12 |
from selenium.webdriver.common.by import By
|
| 13 |
|
| 14 |
-
# --- α
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def load_config():
|
| 19 |
if not os.path.exists(CONFIG_FILE):
|
| 20 |
default = {
|
| 21 |
-
"profile_path": os.path.join(os.getcwd(), "Chrome_Profiles"),
|
| 22 |
"device_presets": [
|
| 23 |
-
{"name": "
|
| 24 |
-
{"name": "
|
| 25 |
-
{"name": "iPhone
|
| 26 |
]
|
| 27 |
}
|
| 28 |
with open(CONFIG_FILE, "w") as f: json.dump(default, f, indent=4)
|
|
@@ -30,30 +33,26 @@ def load_config():
|
|
| 30 |
with open(CONFIG_FILE, "r") as f: return json.load(f)
|
| 31 |
|
| 32 |
config = load_config()
|
| 33 |
-
PROFILE_PATH = config["profile_path"]
|
| 34 |
-
if not os.path.exists(PROFILE_PATH): os.makedirs(PROFILE_PATH)
|
| 35 |
|
| 36 |
# --- αα»αααΆα Logic ---
|
| 37 |
|
| 38 |
def get_profile_list():
|
| 39 |
-
|
| 40 |
-
if not os.path.exists(PROFILE_PATH): return pd.DataFrame(columns=["Status", "Name", "UID", "Device", "Note"])
|
| 41 |
profiles = [d for d in os.listdir(PROFILE_PATH) if os.path.isdir(os.path.join(PROFILE_PATH, d))]
|
| 42 |
rows = []
|
| 43 |
for p in profiles:
|
| 44 |
conf_path = os.path.join(PROFILE_PATH, p, "profile_config.json")
|
| 45 |
status = "π’ Open" if p in active_drivers else "π΄ Closed"
|
| 46 |
-
|
| 47 |
if os.path.exists(conf_path):
|
| 48 |
with open(conf_path, "r") as f:
|
| 49 |
c = json.load(f)
|
| 50 |
-
|
| 51 |
-
device = c.get("device_name", "")
|
| 52 |
note = c.get("note", "")
|
| 53 |
-
rows.append([status, p,
|
| 54 |
-
return pd.DataFrame(rows, columns=["Status", "Name", "
|
| 55 |
|
| 56 |
-
def create_profile(name,
|
| 57 |
if not name: return "β οΈ ααΌααααα
αΌαααααα!", get_profile_list()
|
| 58 |
path = os.path.join(PROFILE_PATH, name)
|
| 59 |
if os.path.exists(path): return "β οΈ ααααααααααΆααα½α
α αΎα!", get_profile_list()
|
|
@@ -62,36 +61,25 @@ def create_profile(name, uid, note, pwd, tfa, email, device_idx, lat, lon):
|
|
| 62 |
preset = config["device_presets"][device_idx]
|
| 63 |
|
| 64 |
data = {
|
| 65 |
-
"profile_name": name, "uid": uid, "note": note,
|
| 66 |
-
"password": pwd, "twofa": tfa, "email": email,
|
| 67 |
"device_name": preset["name"], "device_user_agent": preset["ua"],
|
| 68 |
-
"device_window_size": preset["size"],
|
| 69 |
-
"
|
| 70 |
-
"longitude": float(lon) if lon else None
|
| 71 |
}
|
| 72 |
-
|
| 73 |
with open(os.path.join(path, "profile_config.json"), "w") as f:
|
| 74 |
json.dump(data, f, indent=4)
|
| 75 |
-
|
| 76 |
-
return f"β
ααΆααααααΎα Profile '{name}'!", get_profile_list()
|
| 77 |
|
| 78 |
def open_chrome(name):
|
| 79 |
-
if not name: return "β οΈ ααΌαααααΎαααΎα Profile!"
|
| 80 |
-
if name in active_drivers: return "βΉοΈ
|
| 81 |
|
| 82 |
path = os.path.join(PROFILE_PATH, name)
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
if not os.path.exists(conf_path): return "β αααα·αααΎα Config!"
|
| 86 |
-
|
| 87 |
-
with open(conf_path, "r") as f: conf = json.load(f)
|
| 88 |
|
| 89 |
options = Options()
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
options.binary_location = "/usr/bin/chromium"
|
| 93 |
-
|
| 94 |
-
options.add_argument("--headless") # ααααΌαααααααΎααΎ Server
|
| 95 |
options.add_argument("--no-sandbox")
|
| 96 |
options.add_argument("--disable-dev-shm-usage")
|
| 97 |
options.add_argument(f"user-agent={conf['device_user_agent']}")
|
|
@@ -99,101 +87,76 @@ def open_chrome(name):
|
|
| 99 |
options.add_argument(f"--user-data-dir={path}")
|
| 100 |
|
| 101 |
try:
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
driver = webdriver.Chrome(service=service, options=options)
|
| 107 |
-
else:
|
| 108 |
-
from webdriver_manager.chrome import ChromeDriverManager
|
| 109 |
-
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
|
| 110 |
-
|
| 111 |
-
# ααααααααααααΈααΆαα (Fake Location)
|
| 112 |
-
if conf.get("latitude") and conf.get("longitude"):
|
| 113 |
driver.execute_cdp_cmd("Emulation.setGeolocationOverride", {
|
| 114 |
"latitude": conf["latitude"], "longitude": conf["longitude"], "accuracy": 100
|
| 115 |
})
|
| 116 |
|
| 117 |
active_drivers[name] = driver
|
| 118 |
-
driver.get("https://ifconfig.me")
|
| 119 |
-
|
|
|
|
| 120 |
except Exception as e:
|
| 121 |
return f"β ααα α»α: {str(e)}"
|
| 122 |
|
| 123 |
def close_chrome(name):
|
| 124 |
if name in active_drivers:
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
except: return "β αα·αα’αΆα
αα·αααΆααα"
|
| 130 |
-
return "βΉοΈ Profile ααααα·αααΆααααΆαααΎαααα"
|
| 131 |
|
| 132 |
def delete_profile(name):
|
| 133 |
-
if name in active_drivers: return "β οΈ ααΌααα·α Chrome
|
| 134 |
path = os.path.join(PROFILE_PATH, name)
|
| 135 |
if os.path.exists(path):
|
| 136 |
shutil.rmtree(path)
|
| 137 |
return f"ποΈ ααΆααα»α {name}", get_profile_list()
|
| 138 |
-
return "β οΈ αααα·αααΎα
|
| 139 |
|
| 140 |
-
# --- Gradio UI
|
| 141 |
|
| 142 |
-
with gr.Blocks(title="Chromium
|
| 143 |
-
gr.Markdown("#
|
| 144 |
|
| 145 |
with gr.Tabs():
|
| 146 |
-
# TAB 1: αααααΈ Profile
|
| 147 |
with gr.TabItem("π αααααΈ Profile"):
|
| 148 |
with gr.Row():
|
| 149 |
refresh_btn = gr.Button("π Refresh")
|
| 150 |
-
open_btn = gr.Button("π’ ααΎα Chrome
|
| 151 |
close_btn = gr.Button("π΄ αα·α Chrome", variant="stop")
|
| 152 |
-
del_btn = gr.Button("ποΈ αα»α
|
| 153 |
|
| 154 |
-
|
| 155 |
table = gr.Dataframe(value=get_profile_list(), interactive=False)
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
# α
αΆαααααααααααα Select αααα»α Table
|
| 159 |
-
def on_select(evt: gr.SelectData):
|
| 160 |
-
return evt.value if evt.index[1] == 1 else None
|
| 161 |
|
| 162 |
-
table.select(
|
| 163 |
-
|
| 164 |
refresh_btn.click(get_profile_list, outputs=table)
|
| 165 |
-
open_btn.click(open_chrome, inputs=
|
| 166 |
-
close_btn.click(close_chrome, inputs=
|
| 167 |
-
del_btn.click(delete_profile, inputs=
|
| 168 |
|
| 169 |
-
|
| 170 |
-
with gr.TabItem("β αααααΎα Profile ααααΈ"):
|
| 171 |
with gr.Row():
|
| 172 |
-
|
| 173 |
-
|
| 174 |
with gr.Row():
|
| 175 |
-
|
| 176 |
-
|
| 177 |
with gr.Row():
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
with gr.Row():
|
| 182 |
-
device_in = gr.Dropdown(
|
| 183 |
-
choices=[d["name"] for d in config["device_presets"]],
|
| 184 |
-
label="ααααΎαααΎαααααααα§ααααα (Device)", type="index", value=0
|
| 185 |
-
)
|
| 186 |
-
lat_in = gr.Textbox(label="Latitude (ααΈααΆαααααααααααΆα)")
|
| 187 |
-
lon_in = gr.Textbox(label="Longitude (ααΈααΆαααααααααααΆα)")
|
| 188 |
-
|
| 189 |
-
create_btn = gr.Button("β αααααΎα Profile α₯α‘αΌαααα", variant="primary")
|
| 190 |
-
create_msg = gr.Textbox(label="αααααα")
|
| 191 |
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
outputs=[create_msg, table]
|
| 196 |
-
)
|
| 197 |
|
|
|
|
| 198 |
if __name__ == "__main__":
|
| 199 |
-
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
import shutil
|
|
|
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
import gradio as gr
|
| 6 |
from selenium import webdriver
|
| 7 |
from selenium.webdriver.chrome.service import Service
|
| 8 |
from selenium.webdriver.chrome.options import Options
|
|
|
|
| 9 |
from selenium.webdriver.common.by import By
|
| 10 |
|
| 11 |
+
# --- ααΆααααααααααΌααααα»ααα·αααααα (Paths) ---
|
| 12 |
+
# ααααΎ Folder αααα»α App ααααΆααααΎααααΈα±αα Hugging Face ααΎαααΎα
|
| 13 |
+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 14 |
+
PROFILE_PATH = os.path.join(BASE_DIR, "profiles")
|
| 15 |
+
CONFIG_FILE = os.path.join(BASE_DIR, "config_hf.json")
|
| 16 |
+
|
| 17 |
+
if not os.path.exists(PROFILE_PATH):
|
| 18 |
+
os.makedirs(PROFILE_PATH)
|
| 19 |
+
|
| 20 |
+
active_drivers = {}
|
| 21 |
|
| 22 |
def load_config():
|
| 23 |
if not os.path.exists(CONFIG_FILE):
|
| 24 |
default = {
|
|
|
|
| 25 |
"device_presets": [
|
| 26 |
+
{"name": "Windows Desktop", "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "size": "1920,1080"},
|
| 27 |
+
{"name": "Android Mobile", "ua": "Mozilla/5.0 (Linux; Android 13; SM-S901B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36", "size": "360,800"},
|
| 28 |
+
{"name": "iPhone Pro", "ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1", "size": "393,852"}
|
| 29 |
]
|
| 30 |
}
|
| 31 |
with open(CONFIG_FILE, "w") as f: json.dump(default, f, indent=4)
|
|
|
|
| 33 |
with open(CONFIG_FILE, "r") as f: return json.load(f)
|
| 34 |
|
| 35 |
config = load_config()
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# --- αα»αααΆα Logic ---
|
| 38 |
|
| 39 |
def get_profile_list():
|
| 40 |
+
if not os.path.exists(PROFILE_PATH): return pd.DataFrame(columns=["Status", "Name", "Device", "Note"])
|
|
|
|
| 41 |
profiles = [d for d in os.listdir(PROFILE_PATH) if os.path.isdir(os.path.join(PROFILE_PATH, d))]
|
| 42 |
rows = []
|
| 43 |
for p in profiles:
|
| 44 |
conf_path = os.path.join(PROFILE_PATH, p, "profile_config.json")
|
| 45 |
status = "π’ Open" if p in active_drivers else "π΄ Closed"
|
| 46 |
+
device, note = "Unknown", ""
|
| 47 |
if os.path.exists(conf_path):
|
| 48 |
with open(conf_path, "r") as f:
|
| 49 |
c = json.load(f)
|
| 50 |
+
device = c.get("device_name", "N/A")
|
|
|
|
| 51 |
note = c.get("note", "")
|
| 52 |
+
rows.append([status, p, device, note])
|
| 53 |
+
return pd.DataFrame(rows, columns=["Status", "Name", "Device", "Note"])
|
| 54 |
|
| 55 |
+
def create_profile(name, note, pwd, email, device_idx, lat, lon):
|
| 56 |
if not name: return "β οΈ ααΌααααα
αΌαααααα!", get_profile_list()
|
| 57 |
path = os.path.join(PROFILE_PATH, name)
|
| 58 |
if os.path.exists(path): return "β οΈ ααααααααααΆααα½α
α αΎα!", get_profile_list()
|
|
|
|
| 61 |
preset = config["device_presets"][device_idx]
|
| 62 |
|
| 63 |
data = {
|
|
|
|
|
|
|
| 64 |
"device_name": preset["name"], "device_user_agent": preset["ua"],
|
| 65 |
+
"device_window_size": preset["size"], "note": note,
|
| 66 |
+
"password": pwd, "email": email,
|
| 67 |
+
"latitude": float(lat) if lat else None, "longitude": float(lon) if lon else None
|
| 68 |
}
|
|
|
|
| 69 |
with open(os.path.join(path, "profile_config.json"), "w") as f:
|
| 70 |
json.dump(data, f, indent=4)
|
| 71 |
+
return f"β
αααααΎα Profile '{name}' αααααα!", get_profile_list()
|
|
|
|
| 72 |
|
| 73 |
def open_chrome(name):
|
| 74 |
+
if not name: return "β οΈ ααΌαααααΎαααΎα Profile ααΈααΆααΆα!"
|
| 75 |
+
if name in active_drivers: return "βΉοΈ αααα»αααΎααα½α
α αΎα"
|
| 76 |
|
| 77 |
path = os.path.join(PROFILE_PATH, name)
|
| 78 |
+
with open(os.path.join(path, "profile_config.json"), "r") as f: conf = json.load(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
options = Options()
|
| 81 |
+
options.binary_location = "/usr/bin/chromium"
|
| 82 |
+
options.add_argument("--headless=new") # ααααΆαααααα»ααααααΆαα Server
|
|
|
|
|
|
|
|
|
|
| 83 |
options.add_argument("--no-sandbox")
|
| 84 |
options.add_argument("--disable-dev-shm-usage")
|
| 85 |
options.add_argument(f"user-agent={conf['device_user_agent']}")
|
|
|
|
| 87 |
options.add_argument(f"--user-data-dir={path}")
|
| 88 |
|
| 89 |
try:
|
| 90 |
+
service = Service(executable_path="/usr/bin/chromedriver")
|
| 91 |
+
driver = webdriver.Chrome(service=service, options=options)
|
| 92 |
+
|
| 93 |
+
if conf.get("latitude"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
driver.execute_cdp_cmd("Emulation.setGeolocationOverride", {
|
| 95 |
"latitude": conf["latitude"], "longitude": conf["longitude"], "accuracy": 100
|
| 96 |
})
|
| 97 |
|
| 98 |
active_drivers[name] = driver
|
| 99 |
+
driver.get("https://ifconfig.me")
|
| 100 |
+
ip = driver.find_element(By.TAG_NAME, "body").text
|
| 101 |
+
return f"β
ααΆαααΎα {name} | IP: {ip}"
|
| 102 |
except Exception as e:
|
| 103 |
return f"β ααα α»α: {str(e)}"
|
| 104 |
|
| 105 |
def close_chrome(name):
|
| 106 |
if name in active_drivers:
|
| 107 |
+
active_drivers[name].quit()
|
| 108 |
+
del active_drivers[name]
|
| 109 |
+
return f"β
ααΆααα·α {name}"
|
| 110 |
+
return "βΉοΈ αα·αααΆααααΆαααΎααα"
|
|
|
|
|
|
|
| 111 |
|
| 112 |
def delete_profile(name):
|
| 113 |
+
if name in active_drivers: return "β οΈ ααΌααα·α Chrome αα»ααα»α!", get_profile_list()
|
| 114 |
path = os.path.join(PROFILE_PATH, name)
|
| 115 |
if os.path.exists(path):
|
| 116 |
shutil.rmtree(path)
|
| 117 |
return f"ποΈ ααΆααα»α {name}", get_profile_list()
|
| 118 |
+
return "β οΈ αααα·αααΎα", get_profile_list()
|
| 119 |
|
| 120 |
+
# --- Gradio UI ---
|
| 121 |
|
| 122 |
+
with gr.Blocks(title="Chromium HF", theme=gr.themes.Soft()) as demo:
|
| 123 |
+
gr.Markdown("# π Chromium Profile Manager (HF Optimized)")
|
| 124 |
|
| 125 |
with gr.Tabs():
|
|
|
|
| 126 |
with gr.TabItem("π αααααΈ Profile"):
|
| 127 |
with gr.Row():
|
| 128 |
refresh_btn = gr.Button("π Refresh")
|
| 129 |
+
open_btn = gr.Button("π’ ααΎα Chrome", variant="primary")
|
| 130 |
close_btn = gr.Button("π΄ αα·α Chrome", variant="stop")
|
| 131 |
+
del_btn = gr.Button("ποΈ αα»α")
|
| 132 |
|
| 133 |
+
log = gr.Textbox(label="ααααΆαααΆα")
|
| 134 |
table = gr.Dataframe(value=get_profile_list(), interactive=False)
|
| 135 |
+
sel_name = gr.Textbox(label="Profile αααααααΎαααΎα")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
+
table.select(lambda e: e.value if e.index[1] == 1 else None, None, sel_name)
|
|
|
|
| 138 |
refresh_btn.click(get_profile_list, outputs=table)
|
| 139 |
+
open_btn.click(open_chrome, inputs=sel_name, outputs=log).then(get_profile_list, outputs=table)
|
| 140 |
+
close_btn.click(close_chrome, inputs=sel_name, outputs=log).then(get_profile_list, outputs=table)
|
| 141 |
+
del_btn.click(delete_profile, inputs=sel_name, outputs=[log, table])
|
| 142 |
|
| 143 |
+
with gr.TabItem("β αααααΎαααααΈ"):
|
|
|
|
| 144 |
with gr.Row():
|
| 145 |
+
n = gr.Textbox(label="ααααα Profile")
|
| 146 |
+
nt = gr.Textbox(label="α
αααΆα")
|
| 147 |
with gr.Row():
|
| 148 |
+
p = gr.Textbox(label="Password")
|
| 149 |
+
e = gr.Textbox(label="Email")
|
| 150 |
with gr.Row():
|
| 151 |
+
dv = gr.Dropdown(choices=[d["name"] for d in config["device_presets"]], label="α§ααααα", type="index", value=0)
|
| 152 |
+
la = gr.Textbox(label="Latitude")
|
| 153 |
+
lo = gr.Textbox(label="Longitude")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
+
c_btn = gr.Button("β αααααΎα Profile", variant="primary")
|
| 156 |
+
c_msg = gr.Textbox(label="αααααα")
|
| 157 |
+
c_btn.click(create_profile, inputs=[n, nt, p, e, dv, la, lo], outputs=[c_msg, table])
|
|
|
|
|
|
|
| 158 |
|
| 159 |
+
# --- ααΎαααααΎαααΆα (Launch) ---
|
| 160 |
if __name__ == "__main__":
|
| 161 |
+
# αααααα±ααααΎαααΎ HF αααααααΆα Login
|
| 162 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=7860, show_error=True)
|