Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
from flask import Flask, request, jsonify, Response, stream_with_context, render_template, session, redirect, url_for
|
| 3 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 4 |
import google.generativeai as genai
|
|
@@ -80,6 +79,7 @@ GEMINI_MODELS = [
|
|
| 80 |
{"id": "gemini-exp-1206"},
|
| 81 |
{"id": "gemini-2.0-flash-exp"},
|
| 82 |
{"id": "gemini-2.0-flash-thinking-exp-1219"},
|
|
|
|
| 83 |
{"id": "gemini-2.0-pro-exp"},
|
| 84 |
]
|
| 85 |
|
|
@@ -265,19 +265,9 @@ def list_models():
|
|
| 265 |
response = {"object": "list", "data": GEMINI_MODELS}
|
| 266 |
return jsonify(response)
|
| 267 |
|
| 268 |
-
def keep_alive():
|
| 269 |
-
""" 定期向应用自身发送请求,保持活跃 """
|
| 270 |
-
try:
|
| 271 |
-
response = requests.get("http://127.0.0.1:7860/", timeout=10)
|
| 272 |
-
response.raise_for_status()
|
| 273 |
-
print(f"Keep alive ping successful: {response.status_code} at {time.ctime()}")
|
| 274 |
-
except requests.exceptions.RequestException as e:
|
| 275 |
-
print(f"Keep alive ping failed: {e} at {time.ctime()}")
|
| 276 |
|
| 277 |
if __name__ == '__main__':
|
| 278 |
scheduler = BackgroundScheduler()
|
| 279 |
# 设置定时任务,每 12 小时执行一次 keep_alive 函数
|
| 280 |
-
scheduler.add_job(keep_alive, 'interval', hours = 12)
|
| 281 |
-
|
| 282 |
scheduler.start()
|
| 283 |
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
|
|
|
|
|
|
| 1 |
from flask import Flask, request, jsonify, Response, stream_with_context, render_template, session, redirect, url_for
|
| 2 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 3 |
import google.generativeai as genai
|
|
|
|
| 79 |
{"id": "gemini-exp-1206"},
|
| 80 |
{"id": "gemini-2.0-flash-exp"},
|
| 81 |
{"id": "gemini-2.0-flash-thinking-exp-1219"},
|
| 82 |
+
{"id": "gemini-2.0-flash-thinking-exp-01-21"},
|
| 83 |
{"id": "gemini-2.0-pro-exp"},
|
| 84 |
]
|
| 85 |
|
|
|
|
| 265 |
response = {"object": "list", "data": GEMINI_MODELS}
|
| 266 |
return jsonify(response)
|
| 267 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
if __name__ == '__main__':
|
| 270 |
scheduler = BackgroundScheduler()
|
| 271 |
# 设置定时任务,每 12 小时执行一次 keep_alive 函数
|
|
|
|
|
|
|
| 272 |
scheduler.start()
|
| 273 |
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|