Spaces:
Running
Running
Upload 4 files
Browse files- app.py +17 -0
- requirements.txt +2 -1
app.py
CHANGED
@@ -5,6 +5,9 @@ from datetime import datetime
|
|
5 |
import os
|
6 |
import logging
|
7 |
import func
|
|
|
|
|
|
|
8 |
|
9 |
os.environ['TZ'] = 'Asia/Shanghai'
|
10 |
app = Flask(__name__)
|
@@ -251,5 +254,19 @@ def list_models():
|
|
251 |
response = {"object": "list", "data": GEMINI_MODELS}
|
252 |
return jsonify(response)
|
253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
|
255 |
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
|
|
5 |
import os
|
6 |
import logging
|
7 |
import func
|
8 |
+
from apscheduler.schedulers.background import BackgroundScheduler
|
9 |
+
import requests
|
10 |
+
import time
|
11 |
|
12 |
os.environ['TZ'] = 'Asia/Shanghai'
|
13 |
app = Flask(__name__)
|
|
|
254 |
response = {"object": "list", "data": GEMINI_MODELS}
|
255 |
return jsonify(response)
|
256 |
|
257 |
+
def keep_alive():
|
258 |
+
""" 定期向应用自身发送请求,保持活跃 """
|
259 |
+
try:
|
260 |
+
response = requests.get("http://127.0.0.1:7860/", timeout=10)
|
261 |
+
response.raise_for_status()
|
262 |
+
print(f"Keep alive ping successful: {response.status_code} at {time.ctime()}")
|
263 |
+
except requests.exceptions.RequestException as e:
|
264 |
+
print(f"Keep alive ping failed: {e} at {time.ctime()}")
|
265 |
+
|
266 |
if __name__ == '__main__':
|
267 |
+
scheduler = BackgroundScheduler()
|
268 |
+
# 设置定时任务,每 10 分钟执行一次 keep_alive 函数
|
269 |
+
scheduler.add_job(keep_alive, 'interval', minutes=10)
|
270 |
+
# 启动调度器
|
271 |
+
scheduler.start()
|
272 |
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
requirements.txt
CHANGED
@@ -4,4 +4,5 @@ requests==2.26.0
|
|
4 |
Werkzeug==2.0.3
|
5 |
google==3.0.0
|
6 |
google-generativeai==0.8.3
|
7 |
-
pillow==10.4.0
|
|
|
|
4 |
Werkzeug==2.0.3
|
5 |
google==3.0.0
|
6 |
google-generativeai==0.8.3
|
7 |
+
pillow==10.4.0
|
8 |
+
apscheduler
|