-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
77 lines (62 loc) · 2.01 KB
/
app.py
File metadata and controls
77 lines (62 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from flask import Flask, jsonify, request
import requests as http
app = Flask(__name__)
@app.route("/healthz", methods=["GET"])
def healthz():
return jsonify({"status": "ok"})
@app.route("/models", methods=["GET"])
def get_models():
try:
r = http.get(
"https://huggingface.co/api/models",
params={"sort": "downloads", "direction": "-1", "limit": "5"},
timeout=10,
)
r.raise_for_status()
return jsonify(r.json())
except http.exceptions.RequestException as e:
return jsonify({"error": str(e)}), 500
@app.route("/models/<path:model_id>", methods=["GET"])
def get_model(model_id):
try:
r = http.get(
f"https://huggingface.co/api/models/{model_id}",
timeout=10,
)
r.raise_for_status()
return jsonify(r.json())
except http.exceptions.RequestException as e:
return jsonify({"error": str(e)}), 500
@app.route("/llm/models", methods=["GET"])
def get_llm_models():
try:
r = http.get("https://openrouter.ai/api/v1/models", timeout=10)
r.raise_for_status()
return jsonify(r.json())
except http.exceptions.RequestException as e:
return jsonify({"error": str(e)}), 500
@app.route("/nasa", methods=["GET"])
def get_nasa():
try:
r = http.get(
"https://api.nasa.gov/planetary/apod",
params={"api_key": "DEMO_KEY"},
timeout=10,
)
r.raise_for_status()
return jsonify(r.json())
except http.exceptions.RequestException as e:
return jsonify({"error": str(e)}), 500
@app.route("/events", methods=["GET"])
def get_events():
try:
r = http.get(
"https://api.github.com/orgs/speedscale/events",
timeout=10,
)
r.raise_for_status()
return jsonify(r.json())
except http.exceptions.RequestException as e:
return jsonify({"error": str(e)}), 500
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=5001)