petter2025 commited on
Commit
3c5135b
·
verified ·
1 Parent(s): 765a3c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -27
app.py CHANGED
@@ -45,32 +45,6 @@ def log_memory_usage():
45
  logging.info("Process memory: unknown")
46
  threading.Timer(60, log_memory_usage).start()
47
 
48
- # ----------------------------------------------------------------------
49
- # Keep‑alive (pings public URL every 5 minutes)
50
- # ----------------------------------------------------------------------
51
- def keep_alive():
52
- space_id = os.environ.get('SPACE_ID')
53
- if space_id:
54
- url = f"https://{space_id.replace('/', '-')}.hf.space/"
55
- logging.info(f"Using external URL for keep‑alive: {url}")
56
- else:
57
- # Fallback: try to guess the URL from the Space's name?
58
- # We'll use localhost as a last resort.
59
- url = "http://127.0.0.1:7860/"
60
- logging.warning("No SPACE_ID found, using localhost – will not prevent sleep!")
61
-
62
- while True:
63
- time.sleep(300) # every 5 minutes
64
- try:
65
- req = urllib.request.Request(url, headers={'User-Agent': 'ARF-KeepAlive/1.0'})
66
- with urllib.request.urlopen(req, timeout=30) as response:
67
- status = response.getcode()
68
- logging.info(f"Keep‑alive ping: {status}")
69
- except Exception as e:
70
- logging.warning(f"Keep‑alive failed: {e}")
71
-
72
- threading.Thread(target=keep_alive, daemon=True).start()
73
-
74
  # ----------------------------------------------------------------------
75
  # Plotly
76
  # ----------------------------------------------------------------------
@@ -190,7 +164,7 @@ async def handle_infra_with_governance(fault_type, context_window, session_state
190
  return output, session_state
191
 
192
  # ----------------------------------------------------------------------
193
- # MCMC (Metropolis‑Hastings) – no scipy needed
194
  # ----------------------------------------------------------------------
195
  class MHMCMC:
196
  def __init__(self, log_target, proposal_sd=0.1):
 
45
  logging.info("Process memory: unknown")
46
  threading.Timer(60, log_memory_usage).start()
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  # ----------------------------------------------------------------------
49
  # Plotly
50
  # ----------------------------------------------------------------------
 
164
  return output, session_state
165
 
166
  # ----------------------------------------------------------------------
167
+ # MCMC (Metropolis‑Hastings)
168
  # ----------------------------------------------------------------------
169
  class MHMCMC:
170
  def __init__(self, log_target, proposal_sd=0.1):