Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,8 @@ from PIL import Image
|
|
| 16 |
import json
|
| 17 |
import requests
|
| 18 |
import os
|
|
|
|
|
|
|
| 19 |
# os.environ["HUGGINGFACEHUB_API_TOKEN"]="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1"
|
| 20 |
|
| 21 |
# Initialize FastAPI app
|
|
@@ -85,8 +87,23 @@ chain_parallel = RunnableParallel({'chat_nutrition_prompt':chain1,
|
|
| 85 |
|
| 86 |
@app.get("/")
|
| 87 |
def read_root():
|
|
|
|
| 88 |
return {"message": "This is My Nutrionguid App FAST"}
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
@app.post("/predictNUT")
|
| 91 |
async def predict_image_and_nutrition(file: UploadFile = File(...)):
|
| 92 |
try:
|
|
|
|
| 16 |
import json
|
| 17 |
import requests
|
| 18 |
import os
|
| 19 |
+
import time
|
| 20 |
+
from datetime import datetime
|
| 21 |
# os.environ["HUGGINGFACEHUB_API_TOKEN"]="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1"
|
| 22 |
|
| 23 |
# Initialize FastAPI app
|
|
|
|
| 87 |
|
| 88 |
@app.get("/")
|
| 89 |
def read_root():
|
| 90 |
+
keep_alive()
|
| 91 |
return {"message": "This is My Nutrionguid App FAST"}
|
| 92 |
+
|
| 93 |
+
def keep_alive(space_url="https://1mb1-nutritionguide.hf.space/", interval_hours=5):
|
| 94 |
+
while True:
|
| 95 |
+
try:
|
| 96 |
+
print(f"🔄 Pinging {space_url} at {datetime.now()}")
|
| 97 |
+
response = requests.get(space_url)
|
| 98 |
+
|
| 99 |
+
if response.status_code == 200:
|
| 100 |
+
print("")
|
| 101 |
+
else:
|
| 102 |
+
print("")
|
| 103 |
+
except Exception as e:
|
| 104 |
+
print("")
|
| 105 |
+
|
| 106 |
+
time.sleep(interval_hours * 3600)
|
| 107 |
@app.post("/predictNUT")
|
| 108 |
async def predict_image_and_nutrition(file: UploadFile = File(...)):
|
| 109 |
try:
|