sghorbal commited on
Commit
55df599
·
1 Parent(s): 0feb316
Files changed (3) hide show
  1. README.md +2 -3
  2. app.py +7 -12
  3. start.sh +2 -0
README.md CHANGED
@@ -3,9 +3,8 @@ title: Keep Alive
3
  emoji: 🔥
4
  colorFrom: pink
5
  colorTo: green
6
- sdk: gradio
7
- sdk_version: 5.26.0
8
- app_file: app.py
9
  pinned: false
10
  ---
11
 
 
3
  emoji: 🔥
4
  colorFrom: pink
5
  colorTo: green
6
+ sdk: docker
7
+ app_file: start.sh
 
8
  pinned: false
9
  ---
10
 
app.py CHANGED
@@ -7,11 +7,10 @@ from fastapi.responses import JSONResponse
7
  import gradio as gr
8
 
9
  URLS_FILE = "urls.json"
10
- INTERVAL = 3600 # 1 heure en secondes
11
 
12
  app = FastAPI()
13
 
14
- # --- Gestion des URLs ---
15
  def load_urls():
16
  if os.path.exists(URLS_FILE):
17
  with open(URLS_FILE, "r") as f:
@@ -37,28 +36,25 @@ def remove_url(url):
37
  return urls
38
 
39
  def ping_all():
40
- urls = load_urls()
41
- for url in urls:
42
  try:
43
  requests.get(url, timeout=5)
44
- print(f"[OK] Ping: {url}")
45
  except Exception as e:
46
  print(f"[ERR] {url} -> {e}")
47
 
48
- # --- Scheduler (appel régulier toutes les heures) ---
49
  def schedule_ping():
50
  ping_all()
51
  threading.Timer(INTERVAL, schedule_ping).start()
52
 
53
- # Démarrage automatique au lancement
54
  schedule_ping()
55
 
56
- # --- Endpoint de vérification ---
57
  @app.get("/check_health")
58
  async def check_health():
59
- return JSONResponse(content={"status": "ok", "message": "App is running"})
60
 
61
- # --- Interface Gradio ---
62
  with gr.Blocks() as interface:
63
  gr.Markdown("## 🌐 Gestionnaire de Keep-Alive")
64
 
@@ -75,7 +71,6 @@ with gr.Blocks() as interface:
75
  add_btn.click(fn=add_url, inputs=input_url, outputs=url_list)
76
  remove_btn.click(fn=remove_url, inputs=input_remove, outputs=url_list)
77
 
78
- # --- Lien entre FastAPI et Gradio ---
79
  @app.get("/")
80
- def gradio_ui():
81
  return gr.mount_gradio_app(app, interface)
 
7
  import gradio as gr
8
 
9
  URLS_FILE = "urls.json"
10
+ INTERVAL = 3600 # 1h
11
 
12
  app = FastAPI()
13
 
 
14
  def load_urls():
15
  if os.path.exists(URLS_FILE):
16
  with open(URLS_FILE, "r") as f:
 
36
  return urls
37
 
38
  def ping_all():
39
+ for url in load_urls():
 
40
  try:
41
  requests.get(url, timeout=5)
42
+ print(f"[OK] {url}")
43
  except Exception as e:
44
  print(f"[ERR] {url} -> {e}")
45
 
 
46
  def schedule_ping():
47
  ping_all()
48
  threading.Timer(INTERVAL, schedule_ping).start()
49
 
50
+ # Lancer au démarrage
51
  schedule_ping()
52
 
 
53
  @app.get("/check_health")
54
  async def check_health():
55
+ return JSONResponse({"status": "ok", "message": "App is running"})
56
 
57
+ # Gradio UI
58
  with gr.Blocks() as interface:
59
  gr.Markdown("## 🌐 Gestionnaire de Keep-Alive")
60
 
 
71
  add_btn.click(fn=add_url, inputs=input_url, outputs=url_list)
72
  remove_btn.click(fn=remove_url, inputs=input_remove, outputs=url_list)
73
 
 
74
  @app.get("/")
75
+ def root():
76
  return gr.mount_gradio_app(app, interface)
start.sh ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/bin/bash
2
+ uvicorn app:app --host 0.0.0.0 --port 7860