Hammad712 commited on
Commit
7b4fd90
·
verified ·
1 Parent(s): 3795af2

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +27 -0
app/main.py CHANGED
@@ -31,6 +31,33 @@ async def root():
31
  logger.info("Root endpoint '/' was hit")
32
  return {"message": "Welcome to the Image Generation API! Visit /docs for API documentation."}
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  # --- Run the app ---
35
  if __name__ == "__main__":
36
  uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)
 
31
  logger.info("Root endpoint '/' was hit")
32
  return {"message": "Welcome to the Image Generation API! Visit /docs for API documentation."}
33
 
34
+
35
+ import requests
36
+ import time
37
+ from datetime import datetime
38
+
39
+ url = "https://hammad712-virtual-try-on.hf.space/"
40
+ # 30 hours in seconds
41
+ INTERVAL_SECONDS = 30 * 60 * 60
42
+
43
+ print(f"Service started. Requests will be sent every 30 hours to: {url}")
44
+
45
+ while True:
46
+ try:
47
+ now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
48
+ response = requests.get(url)
49
+
50
+ if response.status_code == 200:
51
+ print(f"[{now}] Success: {response.json()}")
52
+ else:
53
+ print(f"[{now}] Error {response.status_code}: {response.text}")
54
+
55
+ except Exception as e:
56
+ print(f"An unexpected error occurred: {e}")
57
+
58
+ print(f"Sleeping for 30 hours... Next request at approximately {datetime.fromtimestamp(time.time() + INTERVAL_SECONDS)}")
59
+ time.sleep(INTERVAL_SECONDS)
60
+
61
  # --- Run the app ---
62
  if __name__ == "__main__":
63
  uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)