Spaces:
Sleeping
Sleeping
André Fernandes
commited on
Commit
·
0f764c5
1
Parent(s):
1838cc0
added misc. documentation
Browse files
app.py
CHANGED
@@ -10,7 +10,11 @@ class Model(BaseModel):
|
|
10 |
param_count: Optional[int] = None
|
11 |
|
12 |
|
13 |
-
app = FastAPI(
|
|
|
|
|
|
|
|
|
14 |
|
15 |
models = [Model(id=0, name="CNN"), Model(id=1, name="Transformer")]
|
16 |
id_2_hosted_models = {
|
@@ -25,18 +29,24 @@ model_names_2_id = {
|
|
25 |
def greet_json():
|
26 |
return {"Hello World": "Welcome to my ML Repository API!"}
|
27 |
|
|
|
|
|
|
|
|
|
|
|
28 |
@app.get("/hosted/id/{model_id}")
|
29 |
def get_by_id(model_id: int):
|
30 |
-
|
31 |
if model_id not in id_2_hosted_models:
|
32 |
raise HTTPException(status_code=404, detail=f"Model with id={model_id} not found")
|
33 |
-
|
34 |
return id_2_hosted_models[model_id]
|
35 |
|
36 |
@app.get("/hosted/name/{model_name}")
|
37 |
def get_by_name(model_name: str):
|
|
|
|
|
38 |
model_name = model_name.lower()
|
39 |
-
|
40 |
if model_name not in model_names_2_id:
|
41 |
raise HTTPException(status_code=404, detail=f"Model '{model_name}' not found")
|
42 |
|
|
|
10 |
param_count: Optional[int] = None
|
11 |
|
12 |
|
13 |
+
app = FastAPI(
|
14 |
+
title="ML Repository API",
|
15 |
+
description="API for getting predictions from hosted ML models.",
|
16 |
+
version="0.0.1")
|
17 |
+
|
18 |
|
19 |
models = [Model(id=0, name="CNN"), Model(id=1, name="Transformer")]
|
20 |
id_2_hosted_models = {
|
|
|
29 |
def greet_json():
|
30 |
return {"Hello World": "Welcome to my ML Repository API!"}
|
31 |
|
32 |
+
@app.get("/hosted")
|
33 |
+
def list_models():
|
34 |
+
"List all the hosted models."
|
35 |
+
return models
|
36 |
+
|
37 |
@app.get("/hosted/id/{model_id}")
|
38 |
def get_by_id(model_id: int):
|
39 |
+
"Get a specific model by its ID."
|
40 |
if model_id not in id_2_hosted_models:
|
41 |
raise HTTPException(status_code=404, detail=f"Model with id={model_id} not found")
|
42 |
+
|
43 |
return id_2_hosted_models[model_id]
|
44 |
|
45 |
@app.get("/hosted/name/{model_name}")
|
46 |
def get_by_name(model_name: str):
|
47 |
+
"Get a specific model by its name."
|
48 |
+
|
49 |
model_name = model_name.lower()
|
|
|
50 |
if model_name not in model_names_2_id:
|
51 |
raise HTTPException(status_code=404, detail=f"Model '{model_name}' not found")
|
52 |
|