Spaces:
Runtime error
Runtime error
Topallaj Denis
commited on
Commit
•
0fa1652
1
Parent(s):
2903c7f
Modified post request
Browse files- main.py +3 -2
- static/script.js +9 -1
main.py
CHANGED
@@ -38,7 +38,7 @@ app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
|
38 |
def home() -> FileResponse:
|
39 |
return FileResponse(path="/app/static/index.html", media_type="text/html")
|
40 |
|
41 |
-
@app.
|
42 |
def predict_UniKP_values(sequence: str = Form(...), smiles: str = Form(...)) -> Dict[str, float]:
|
43 |
|
44 |
endpointHandler = EndpointHandler()
|
@@ -69,7 +69,8 @@ class EndpointHandler():
|
|
69 |
# load the vocab and trfm model
|
70 |
self.vocab = WordVocab(vocab_content)
|
71 |
self.trfm = TrfmSeq2seq(len(self.vocab), 256, len(self.vocab), 4)
|
72 |
-
|
|
|
73 |
self.trfm.eval()
|
74 |
|
75 |
# path to the pretrained models
|
|
|
38 |
def home() -> FileResponse:
|
39 |
return FileResponse(path="/app/static/index.html", media_type="text/html")
|
40 |
|
41 |
+
@app.post("/predict")
|
42 |
def predict_UniKP_values(sequence: str = Form(...), smiles: str = Form(...)) -> Dict[str, float]:
|
43 |
|
44 |
endpointHandler = EndpointHandler()
|
|
|
69 |
# load the vocab and trfm model
|
70 |
self.vocab = WordVocab(vocab_content)
|
71 |
self.trfm = TrfmSeq2seq(len(self.vocab), 256, len(self.vocab), 4)
|
72 |
+
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
73 |
+
self.trfm.load_state_dict(torch.load(trfm_path), map_location=device)
|
74 |
self.trfm.eval()
|
75 |
|
76 |
# path to the pretrained models
|
static/script.js
CHANGED
@@ -15,7 +15,15 @@ document.querySelector("#predict-form").addEventListener("submit", async (e) =>
|
|
15 |
});
|
16 |
|
17 |
const prediction = async (sequence, smiles) => {
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
const data = await response.json();
|
20 |
return data;
|
21 |
};
|
|
|
15 |
});
|
16 |
|
17 |
const prediction = async (sequence, smiles) => {
|
18 |
+
// send POST request with FormData
|
19 |
+
const formData = new FormData();
|
20 |
+
formData.append("sequence", sequence);
|
21 |
+
formData.append("smiles", smiles);
|
22 |
+
|
23 |
+
const response = await fetch("/predict", {
|
24 |
+
method: "POST",
|
25 |
+
body: formData,
|
26 |
+
});
|
27 |
const data = await response.json();
|
28 |
return data;
|
29 |
};
|