-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
42 lines (30 loc) · 864 Bytes
/
api.py
File metadata and controls
42 lines (30 loc) · 864 Bytes
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
from chebi_tools.ChEBIStandardizer import ChEBIStandardizer
from chebi_tools.ChEBIGraph import ChEBIGraph
from fastapi import FastAPI
from pydantic import BaseModel
from typing import Optional
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
STD = ChEBIStandardizer()
# graph = ChEBIGraph()
app = FastAPI()
@app.get("/")
async def root():
return "ChEBI tools"
@app.get("/name/{name}/")
async def get_name(name: str):
print(name)
suggested_name = STD.suggest_name(name)
return {"suggested_name": suggested_name}
"""
@app.get("/graph/{name}/")
async def get_subgraph(name:str):
try:
suggested_name = graph.get_subgraph(name, show=True)
return {"suggested_name": suggested_name}
except KeyError:
return {"suggested_name": None}
"""