import gradio as gr from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options import time # 🔧 Driver global driver = None # ✅ Connexion def connexion(login, password): global driver options = Options() driver = webdriver.Chrome(options=options) try: driver.get("https://educonnect.education.gouv.fr/idp/profile/SAML2/Redirect/SSO?execution=e3s1") time.sleep(3) driver.find_element(By.XPATH, "/html/body/div[3]/div/div[2]/div[1]/div/div[2]/button").click() time.sleep(2) driver.find_element(By.XPATH, "/html/body/div[3]/div/div[2]/div[2]/div[3]/div/form/div[1]/input").send_keys(login) driver.find_element(By.XPATH, "/html/body/div[3]/div/div[2]/div[2]/div[3]/div/form/div[2]/div[2]/input").send_keys(password) driver.find_element(By.XPATH, "/html/body/div[3]/div/div[2]/div[2]/div[3]/div/form/div[3]/button").click() time.sleep(5) driver.get("https://wilapa-guyane.com/auth/saml/wayf?callback=https%3A%2F%2Fwilapa-guyane.com%2F#/") time.sleep(5) driver.find_element(By.XPATH, "/html/body/default-styles/div/section/section/div[2]/a/div/i18n/span").click() return "✅ Connecté" except Exception as e: return f"❌ Erreur connexion : {e}" # ✅ Envoyer message def envoyer_message(message, destinataire): global driver try: driver.find_element(By.XPATH, "/html/body/ode-portal/ode-navbar/header/nav/div/ul/li[3]/a").click() time.sleep(3) driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div[1]/div/div/div/button").click() time.sleep(2) champ = driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div[2]/div[2]/div/div[1]/div/div[1]/div/div[1]/div/input") champ.send_keys(destinataire) time.sleep(2) driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div[2]/div[2]/div/div[1]/div/div[1]/div/div[2]").click() champ_msg = driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div[2]/div[2]/div/section/div[1]/div[2]/div/div/p[1]") champ_msg.send_keys(message) driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div[2]/div[2]/div/div[3]/div/div/div/div[1]/button").click() return f"✅ Message envoyé à {destinataire}" except Exception as e: return f"❌ Erreur : {e}" # ✅ Changer devise def changer_devise(valeur): global driver try: champ = driver.find_element(By.XPATH, "/html/body/portal/div[2]/section/div[2]/container/div/div[2]/container/div/div[1]/div[2]/article/div/div/div/input") champ.clear() champ.send_keys(valeur) driver.find_element(By.XPATH, "/html/body/portal/div[2]/section/div[2]/container/div/div[2]/container/div/div[1]/div[2]/article/div/div/button/i18n/span").click() return f"✅ Devise changée : {valeur}" except Exception as e: return f"❌ Erreur : {e}" # 🎨 Interface Gradio with gr.Blocks() as app: gr.HTML("

🤖 Bot Wilapa

") with gr.Tab("Connexion"): login = gr.Textbox(label="Identifiant") password = gr.Textbox(label="Mot de passe", type="password") btn_login = gr.Button("Se connecter") out_login = gr.Textbox() btn_login.click(connexion, inputs=[login, password], outputs=out_login) with gr.Tab("Envoyer message"): message = gr.Textbox(label="Message") dest = gr.Textbox(label="Destinataire") btn_send = gr.Button("Envoyer") out_send = gr.Textbox() btn_send.click(envoyer_message, inputs=[message, dest], outputs=out_send) with gr.Tab("Changer devise"): devise = gr.Textbox(label="Nouvelle valeur") btn_dev = gr.Button("Changer") out_dev = gr.Textbox() btn_dev.click(changer_devise, inputs=devise, outputs=out_dev) app.launch()