vid31 / app.py
malikrf22's picture
Update app.py
0ad6709 verified
import os
import gradio as gr
from huggingface_hub import hf_hub_download
import shutil
import json
# ======================================================
# 1. SETUP LOGIKA APLIKASI
# ======================================================
token_gudang = None
setup_error = None # βœ… Simpan error di variable global
try:
token_gudang = os.environ.get("KUNCI_GUDANG")
# Download script python logika
path_download_logic = hf_hub_download(
repo_id="malikrf22/abcx",
filename="kling_baru.py",
repo_type="dataset",
token=token_gudang
)
shutil.copy(path_download_logic, "kling_logic.py")
# Import UI dan fungsi dari script tersebut
from kling_logic import create_app_ui, set_hf_token
# Set HF Token untuk write access
set_hf_token(token_gudang)
except Exception as e:
setup_error = str(e) # βœ… Simpan error message
print(f"Error Setup Awal: {e}")
def create_app_ui():
with gr.Column(visible=False) as main_interface:
gr.Markdown(f"❌ Gagal memuat logika: {setup_error}")
return main_interface
# ======================================================
# 2. FUNGSI UPDATE PASSWORD
# ======================================================
def get_latest_passwords():
try:
path = hf_hub_download(
repo_id="malikrf22/abcx",
filename="freepik_passwords.json",
repo_type="dataset",
token=token_gudang,
force_download=True
)
with open(path, 'r') as f:
return json.load(f)
except Exception as e:
print(f"Gagal update password: {e}")
return []
# ======================================================
# 3. LOGIKA VERIFIKASI LOGIN
# ======================================================
def verify_login(password):
current_user_db = get_latest_passwords()
if password in current_user_db:
return {
login_row: gr.update(visible=False),
app_row: gr.update(visible=True),
status_box: "βœ… Login Sukses!"
}
else:
return {
login_row: gr.update(visible=True),
app_row: gr.update(visible=False),
status_box: "❌ Sandi salah atau belum terupdate."
}
# ======================================================
# 4. ANTARMUKA UTAMA
# ======================================================
with gr.Blocks(title="Kling Pro Studio") as demo:
with gr.Column(visible=True) as login_row:
gr.Markdown("## πŸ” Login Real-time")
with gr.Group():
password_input = gr.Textbox(label="Kode Akses", type="password")
login_btn = gr.Button("MASUK", variant="primary")
status_box = gr.Textbox(label="Status", interactive=False)
app_row = create_app_ui()
# Event Listeners
login_btn.click(fn=verify_login, inputs=password_input, outputs=[login_row, app_row, status_box])
password_input.submit(fn=verify_login, inputs=password_input, outputs=[login_row, app_row, status_box])
if __name__ == "__main__":
demo.queue(max_size=500, default_concurrency_limit=100).launch()