sghorbal commited on
Commit
4cfb17a
·
1 Parent(s): f644dfd

add defualt urls and url list management system

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -30,30 +30,38 @@ async def basic_auth(request: Request, call_next):
30
 
31
  return await call_next(request)
32
 
33
-
34
  # Liste d'URLs à pinger
35
- url_list = []
 
36
 
37
- # Fonction Gradio pour ajouter / retirer des URLs
38
- def manage_urls(action, url):
 
39
  if action == "Ajouter":
40
- if url not in url_list:
41
  url_list.append(url)
42
- return f"Ajouté: {url}"
43
  elif action == "Supprimer":
44
  if url in url_list:
45
  url_list.remove(url)
46
- return f"Supprimé: {url}"
47
- return "Action invalide"
 
 
 
48
 
49
- # Interface Gradio
50
  interface = gr.Interface(
51
  fn=manage_urls,
52
  inputs=[
53
- gr.Radio(choices=["Ajouter", "Supprimer"], label="Action"),
54
- gr.Textbox(label="URL")
 
 
 
 
 
55
  ],
56
- outputs="text",
57
  title="Gestion des URLs 🔄",
58
  flagging_dir="/tmp/flags"
59
  )
@@ -62,7 +70,6 @@ interface = gr.Interface(
62
  def root_redirect():
63
  return RedirectResponse(url="/gradio")
64
 
65
- # Route pour vérifier que l'app est vivante
66
  @app.get("/check_health")
67
  def check_health():
68
  return JSONResponse(content={"status": "ok", "nb_urls": len(url_list)})
@@ -80,5 +87,5 @@ def ping_loop():
80
 
81
  threading.Thread(target=ping_loop, daemon=True).start()
82
 
83
- # Monter Gradio sur /
84
  gr.mount_gradio_app(app, interface, path="/gradio")
 
30
 
31
  return await call_next(request)
32
 
 
33
  # Liste d'URLs à pinger
34
+ default_urls = os.getenv("DEFAULT_URLS", "")
35
+ url_list = [url.strip() for url in default_urls.split(",") if url.strip()]
36
 
37
+ # Fonction Gradio pour ajouter / retirer des URLs ou mettre à jour la liste
38
+ def manage_urls(action, url, current_urls_textbox):
39
+ global url_list
40
  if action == "Ajouter":
41
+ if url and url not in url_list:
42
  url_list.append(url)
43
+ return f"Ajouté: {url}", "\n".join(url_list)
44
  elif action == "Supprimer":
45
  if url in url_list:
46
  url_list.remove(url)
47
+ return f"Supprimé: {url}", "\n".join(url_list)
48
+ elif action == "Mettre à jour liste":
49
+ url_list = [u.strip() for u in current_urls_textbox.splitlines() if u.strip()]
50
+ return "Liste mise à jour", "\n".join(url_list)
51
+ return "Action invalide", "\n".join(url_list)
52
 
53
+ # Interface Gradio avec textbox contenant la liste complète
54
  interface = gr.Interface(
55
  fn=manage_urls,
56
  inputs=[
57
+ gr.Radio(choices=["Ajouter", "Supprimer", "Mettre à jour liste"], label="Action"),
58
+ gr.Textbox(label="URL"),
59
+ gr.Textbox(value="\n".join(url_list), lines=10, label="Liste d'URLs actuelle"),
60
+ ],
61
+ outputs=[
62
+ gr.Textbox(label="Message"),
63
+ gr.Textbox(label="Liste mise à jour"),
64
  ],
 
65
  title="Gestion des URLs 🔄",
66
  flagging_dir="/tmp/flags"
67
  )
 
70
  def root_redirect():
71
  return RedirectResponse(url="/gradio")
72
 
 
73
  @app.get("/check_health")
74
  def check_health():
75
  return JSONResponse(content={"status": "ok", "nb_urls": len(url_list)})
 
87
 
88
  threading.Thread(target=ping_loop, daemon=True).start()
89
 
90
+ # Monter Gradio sur /gradio
91
  gr.mount_gradio_app(app, interface, path="/gradio")