Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import os
|
|
| 3 |
from starlette.middleware.cors import CORSMiddleware
|
| 4 |
from pydantic import BaseModel
|
| 5 |
import uvicorn
|
|
|
|
| 6 |
import torch
|
| 7 |
from fastapi.encoders import jsonable_encoder
|
| 8 |
from fastapi.responses import JSONResponse
|
|
@@ -18,7 +19,7 @@ app.add_middleware(
|
|
| 18 |
)
|
| 19 |
|
| 20 |
class Query(BaseModel):
|
| 21 |
-
|
| 22 |
|
| 23 |
rob_chem_model = ClassificationModel('roberta', 'seyonec/SMILES_tokenized_PubChem_shard00_160k',use_cuda=False ,args={'evaluate_each_epoch':True , 'evaluate_during_training_verbose':True, 'seed':4})
|
| 24 |
|
|
@@ -26,14 +27,16 @@ rob_chem_model = ClassificationModel('roberta', 'seyonec/SMILES_tokenized_PubChe
|
|
| 26 |
async def c(query:Query):
|
| 27 |
print(query)
|
| 28 |
print(type(query))
|
|
|
|
| 29 |
try:
|
| 30 |
-
predictions, raw_outputs = rob_chem_model.predict([str(query.
|
| 31 |
print(predictions)
|
| 32 |
#json_compatible_item_data = jsonable_encoder(predictions[0])
|
| 33 |
#return JSONResponse(content=json_compatible_item_data)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
except Exception as e:
|
| 39 |
print("Excepted")
|
|
|
|
| 3 |
from starlette.middleware.cors import CORSMiddleware
|
| 4 |
from pydantic import BaseModel
|
| 5 |
import uvicorn
|
| 6 |
+
from typing import List
|
| 7 |
import torch
|
| 8 |
from fastapi.encoders import jsonable_encoder
|
| 9 |
from fastapi.responses import JSONResponse
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
class Query(BaseModel):
|
| 22 |
+
smiles :List[str]
|
| 23 |
|
| 24 |
rob_chem_model = ClassificationModel('roberta', 'seyonec/SMILES_tokenized_PubChem_shard00_160k',use_cuda=False ,args={'evaluate_each_epoch':True , 'evaluate_during_training_verbose':True, 'seed':4})
|
| 25 |
|
|
|
|
| 27 |
async def c(query:Query):
|
| 28 |
print(query)
|
| 29 |
print(type(query))
|
| 30 |
+
query_dict = query.dict()
|
| 31 |
try:
|
| 32 |
+
predictions, raw_outputs = rob_chem_model.predict([str(query.smiles)])
|
| 33 |
print(predictions)
|
| 34 |
#json_compatible_item_data = jsonable_encoder(predictions[0])
|
| 35 |
#return JSONResponse(content=json_compatible_item_data)
|
| 36 |
+
query_dict.update({"predictions":predictions})
|
| 37 |
+
#answer = {"prediction":predictions[0]}
|
| 38 |
+
#return {'response':answer}
|
| 39 |
+
return query_dict
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
print("Excepted")
|