File size: 1,855 Bytes
1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 414516d 1918287 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | import gradio as gr
import hashlib
import os
UPLOAD_FOLDER = "uploads"
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
USERS = {
"admin": hashlib.sha256("admin123".encode()).hexdigest(),
"demo": hashlib.sha256("demo".encode()).hexdigest()
}
session = {"user": None}
# ======================
# BACKEND
# ======================
def login(username, password):
h = hashlib.sha256(password.encode()).hexdigest()
if username in USERS and USERS[username] == h:
session["user"] = username
return "✅ Connecté", gr.update(visible=True)
return "❌ Mauvais login", gr.update(visible=False)
def upload(file):
if session["user"] is None:
return "❌ Non connecté"
if file is None:
return "❌ Aucun fichier"
path = os.path.join(UPLOAD_FOLDER, file.name)
with open(path, "wb") as f:
f.write(file.read())
return f"✅ Upload : {file.name}"
def list_files():
if session["user"] is None:
return []
return os.listdir(UPLOAD_FOLDER)
# ======================
# UI (GRADIO)
# ======================
with gr.Blocks() as app:
# LOGIN
with gr.Column() as login_ui:
gr.Markdown("# 🔐 Login")
user = gr.Textbox(label="Username")
pw = gr.Textbox(label="Password", type="password")
btn = gr.Button("Login")
status = gr.Textbox()
# APP
with gr.Column(visible=False) as main_ui:
gr.Markdown("# 📁 Gestionnaire")
file = gr.File()
btn_upload = gr.Button("Upload")
upload_status = gr.Textbox()
btn_list = gr.Button("Lister fichiers")
files = gr.JSON()
# EVENTS
btn.click(login, [user, pw], [status, main_ui])
btn_upload.click(upload, file, upload_status)
btn_list.click(list_files, None, files)
app.launch() |