Spaces:
Runtime error
Runtime error
Topallaj Denis
commited on
Commit
•
37db1e1
1
Parent(s):
027aeb0
complete predict endpoint
Browse files- main.py +9 -14
- requirements.txt +2 -1
- static/index.html +0 -49
- static/script.js +0 -35
- static/styles.css +0 -80
main.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
-
from fastapi.staticfiles import StaticFiles
|
4 |
-
from fastapi.responses import FileResponse
|
5 |
from typing import Dict, List, Any, Tuple
|
6 |
import pickle
|
7 |
import math
|
@@ -13,6 +11,7 @@ from build_vocab import WordVocab
|
|
13 |
from pretrain_trfm import TrfmSeq2seq
|
14 |
from transformers import T5EncoderModel, T5Tokenizer
|
15 |
import numpy as np
|
|
|
16 |
|
17 |
app = FastAPI()
|
18 |
|
@@ -30,25 +29,21 @@ tokenizer = T5Tokenizer.from_pretrained(
|
|
30 |
model = T5EncoderModel.from_pretrained(
|
31 |
"Rostlab/prot_t5_xl_half_uniref50-enc")
|
32 |
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
@app.get("/")
|
38 |
-
def home():
|
39 |
-
smiles = "CC1=CC(=C(C=C1)C(=O)O)O"
|
40 |
-
sequence = "MGLSDGEWQLVLNVWGKVEADIPGHGQEVLIRLFKGHPETLEKFDKFKHLKSEDEMKASEDLKKAGVTVLTALGAILKKKGHHEAELKPLAQSHATKHKIPIKYLEFISEAIIHVLHSRHPGNFGADAQGAMNKALELFRKDIAAKYKELGYQG"
|
41 |
endpointHandler = EndpointHandler()
|
42 |
result = endpointHandler.predict({
|
43 |
"inputs": {
|
44 |
-
"sequence": sequence,
|
45 |
-
"smiles": smiles
|
46 |
}
|
47 |
})
|
48 |
|
49 |
return result
|
50 |
-
# return FileResponse(path="/app/static/index.html", media_type="text/html")
|
51 |
-
|
52 |
|
53 |
class EndpointHandler():
|
54 |
def __init__(self, path=""):
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
3 |
from typing import Dict, List, Any, Tuple
|
4 |
import pickle
|
5 |
import math
|
|
|
11 |
from pretrain_trfm import TrfmSeq2seq
|
12 |
from transformers import T5EncoderModel, T5Tokenizer
|
13 |
import numpy as np
|
14 |
+
import pydantic
|
15 |
|
16 |
app = FastAPI()
|
17 |
|
|
|
29 |
model = T5EncoderModel.from_pretrained(
|
30 |
"Rostlab/prot_t5_xl_half_uniref50-enc")
|
31 |
|
32 |
+
class Item(pydantic.BaseModel):
|
33 |
+
sequence: str
|
34 |
+
smiles: str
|
35 |
|
36 |
+
@app.get("/predict")
|
37 |
+
def predict(item: Item):
|
|
|
|
|
|
|
|
|
|
|
38 |
endpointHandler = EndpointHandler()
|
39 |
result = endpointHandler.predict({
|
40 |
"inputs": {
|
41 |
+
"sequence": item.sequence,
|
42 |
+
"smiles": item.smiles
|
43 |
}
|
44 |
})
|
45 |
|
46 |
return result
|
|
|
|
|
47 |
|
48 |
class EndpointHandler():
|
49 |
def __init__(self, path=""):
|
requirements.txt
CHANGED
@@ -10,4 +10,5 @@ SentencePiece==0.2.0
|
|
10 |
scikit-learn==1.2.2
|
11 |
openpyxl==3.1.2
|
12 |
torch==2.2.1
|
13 |
-
python-multipart==0.0.9
|
|
|
|
10 |
scikit-learn==1.2.2
|
11 |
openpyxl==3.1.2
|
12 |
torch==2.2.1
|
13 |
+
python-multipart==0.0.9
|
14 |
+
pydantic==2.6.4
|
static/index.html
DELETED
@@ -1,49 +0,0 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8" />
|
5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6 |
-
<script src="./script.js" defer></script>
|
7 |
-
<link rel="stylesheet" href="./styles.css" />
|
8 |
-
|
9 |
-
<title>UniKP App</title>
|
10 |
-
</head>
|
11 |
-
<body>
|
12 |
-
<div class="container">
|
13 |
-
<h1>UniKP App</h1>
|
14 |
-
<p>
|
15 |
-
This HF app uses the UniKP framework. Be sure to check it out on
|
16 |
-
<a href="https://github.com/Luo-SynBioLab/UniKP"> GitHub</a>
|
17 |
-
</p>
|
18 |
-
<form id="predict-form">
|
19 |
-
<label for="sequence">Sequence:</label>
|
20 |
-
<input
|
21 |
-
type="text"
|
22 |
-
id="sequence"
|
23 |
-
name="sequence"
|
24 |
-
placeholder="Enter sequence here"
|
25 |
-
required
|
26 |
-
/>
|
27 |
-
<label for="substrate">Substrate (SMILES):</label>
|
28 |
-
<input
|
29 |
-
type="text"
|
30 |
-
id="substrate"
|
31 |
-
name="smiles"
|
32 |
-
placeholder="Enter substrate SMILES here"
|
33 |
-
required
|
34 |
-
/>
|
35 |
-
<input type="submit" value="Predict" />
|
36 |
-
</form>
|
37 |
-
</div>
|
38 |
-
<div id="result-container">
|
39 |
-
<div id="result" class="container">
|
40 |
-
<h3>Km</h3>
|
41 |
-
<p id="km-result"></p>
|
42 |
-
<h3>Kcat</h3>
|
43 |
-
<p id="kcat-result"></p>
|
44 |
-
<h3>Vmax</h3>
|
45 |
-
<p id="vmax-result"></p>
|
46 |
-
</div>
|
47 |
-
</div>
|
48 |
-
</body>
|
49 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static/script.js
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
"use strict";
|
2 |
-
|
3 |
-
document.querySelector("#predict-form").addEventListener("submit", async (e) => {
|
4 |
-
e.preventDefault();
|
5 |
-
const sequence = document.querySelector("#sequence").value;
|
6 |
-
const smiles = document.querySelector("#substrate").value;
|
7 |
-
|
8 |
-
console.log(sequence);
|
9 |
-
|
10 |
-
const data = await prediction(sequence, smiles);
|
11 |
-
|
12 |
-
document.querySelector("#km-result").innerText = data.km;
|
13 |
-
document.querySelector("#kcat-result").innerText = data.kcat;
|
14 |
-
document.querySelector("#vmax-result").innerText = data.vmax;
|
15 |
-
});
|
16 |
-
|
17 |
-
const prediction = async (sequence, smiles) => {
|
18 |
-
|
19 |
-
/*const response = await fetch("/predict", {
|
20 |
-
method: "POST",
|
21 |
-
body: {
|
22 |
-
sequence: sequence,
|
23 |
-
smiles: smiles,
|
24 |
-
}
|
25 |
-
});
|
26 |
-
const data = await response.json();
|
27 |
-
return data;
|
28 |
-
*/
|
29 |
-
|
30 |
-
return {
|
31 |
-
km: 1,
|
32 |
-
kcat: 2,
|
33 |
-
vmax: 3,
|
34 |
-
}
|
35 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static/styles.css
DELETED
@@ -1,80 +0,0 @@
|
|
1 |
-
/* styles.css */
|
2 |
-
|
3 |
-
/* Resetting default margin and padding */
|
4 |
-
* {
|
5 |
-
margin: 0;
|
6 |
-
padding: 0;
|
7 |
-
box-sizing: border-box;
|
8 |
-
}
|
9 |
-
|
10 |
-
/* Global styles */
|
11 |
-
body {
|
12 |
-
font-family: Arial, sans-serif;
|
13 |
-
background-color: #f0f0f0;
|
14 |
-
color: #333;
|
15 |
-
}
|
16 |
-
|
17 |
-
.container {
|
18 |
-
max-width: 600px;
|
19 |
-
margin: 20px auto;
|
20 |
-
padding: 20px;
|
21 |
-
background-color: #fff;
|
22 |
-
border-radius: 8px;
|
23 |
-
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
24 |
-
}
|
25 |
-
|
26 |
-
h1 {
|
27 |
-
font-size: 24px;
|
28 |
-
margin-bottom: 20px;
|
29 |
-
}
|
30 |
-
|
31 |
-
p {
|
32 |
-
margin-bottom: 20px;
|
33 |
-
}
|
34 |
-
|
35 |
-
form {
|
36 |
-
margin-bottom: 20px;
|
37 |
-
}
|
38 |
-
|
39 |
-
label {
|
40 |
-
display: block;
|
41 |
-
margin-bottom: 5px;
|
42 |
-
}
|
43 |
-
|
44 |
-
input[type="text"] {
|
45 |
-
width: 100%;
|
46 |
-
padding: 10px;
|
47 |
-
margin-bottom: 10px;
|
48 |
-
border: 1px solid #ccc;
|
49 |
-
border-radius: 4px;
|
50 |
-
}
|
51 |
-
|
52 |
-
input[type="submit"] {
|
53 |
-
background-color: #007bff;
|
54 |
-
color: #fff;
|
55 |
-
border: none;
|
56 |
-
padding: 10px 20px;
|
57 |
-
border-radius: 4px;
|
58 |
-
cursor: pointer;
|
59 |
-
}
|
60 |
-
|
61 |
-
input[type="submit"]:hover {
|
62 |
-
background-color: #0056b3;
|
63 |
-
}
|
64 |
-
|
65 |
-
/* Result container styles */
|
66 |
-
#result-container #result {
|
67 |
-
background-color: #f9f9f9;
|
68 |
-
padding: 20px;
|
69 |
-
border-radius: 8px;
|
70 |
-
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
|
71 |
-
}
|
72 |
-
|
73 |
-
#result h3 {
|
74 |
-
font-size: 18px;
|
75 |
-
margin-bottom: 10px;
|
76 |
-
}
|
77 |
-
|
78 |
-
#result p {
|
79 |
-
margin-bottom: 10px;
|
80 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|