Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,9 @@ import torch
|
|
| 5 |
import random
|
| 6 |
import os
|
| 7 |
import numpy as np
|
|
|
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
random.seed(4)
|
| 11 |
np.random.seed(4)
|
|
@@ -13,34 +15,16 @@ torch.manual_seed(4)
|
|
| 13 |
np.random.seed(4)
|
| 14 |
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
allow_origins=["*"],
|
| 25 |
-
allow_credentials=True,
|
| 26 |
-
allow_methods=["*"],
|
| 27 |
-
allow_headers=["*"],
|
| 28 |
-
)
|
| 29 |
-
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})
|
| 30 |
|
| 31 |
-
class Query(BaseModel):
|
| 32 |
-
query :str
|
| 33 |
|
| 34 |
-
@app.post("/ToxicityPrediction")
|
| 35 |
-
async def c(query:Query):
|
| 36 |
-
try:
|
| 37 |
-
predictions, raw_outputs = rob_chem_model.predict([str(query.query)])
|
| 38 |
-
st.write("Received request")
|
| 39 |
-
return {"prediction":predictions[0]}
|
| 40 |
-
except Exception as e:
|
| 41 |
-
raise HTTPException(detail = str(e) , status_code = 500)
|
| 42 |
-
if __name__ == "__main__":
|
| 43 |
-
uvicorn.run(app, host="0.0.0.0", port=5566)
|
| 44 |
|
| 45 |
# Set the Streamlit app title
|
| 46 |
st.title("Molecule Toxicity Predictions")
|
|
@@ -50,9 +34,9 @@ path = 'ToxicityPrediction/Models/transformers/checkpoint-149-epoch-1'
|
|
| 50 |
|
| 51 |
# Load the model from the stage
|
| 52 |
#loaded_model = ClassificationModel('roberta', path, use_cuda = False)
|
| 53 |
-
#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})
|
| 54 |
# Predict based on the input
|
| 55 |
-
rob_chem_model.model.eval()
|
| 56 |
#target_name= st.text_input('Enter a SMILES string:')
|
| 57 |
target_name = st.text_area("Enter smiles (one per line):", "")
|
| 58 |
|
|
|
|
| 5 |
import random
|
| 6 |
import os
|
| 7 |
import numpy as np
|
| 8 |
+
import subprocess
|
| 9 |
|
| 10 |
+
import requests
|
| 11 |
|
| 12 |
random.seed(4)
|
| 13 |
np.random.seed(4)
|
|
|
|
| 15 |
np.random.seed(4)
|
| 16 |
|
| 17 |
|
| 18 |
+
def start_fastapi():
|
| 19 |
+
subprocess.Popen(["uvicorn", "fastapi_app:app", "--host", "0.0.0.0", "--port", "5566"])
|
| 20 |
+
|
| 21 |
+
# Start the FastAPI server
|
| 22 |
+
start_fastapi()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
|
|
|
|
|
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Set the Streamlit app title
|
| 30 |
st.title("Molecule Toxicity Predictions")
|
|
|
|
| 34 |
|
| 35 |
# Load the model from the stage
|
| 36 |
#loaded_model = ClassificationModel('roberta', path, use_cuda = False)
|
| 37 |
+
#----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})
|
| 38 |
# Predict based on the input
|
| 39 |
+
#rob_chem_model.model.eval() ----
|
| 40 |
#target_name= st.text_input('Enter a SMILES string:')
|
| 41 |
target_name = st.text_area("Enter smiles (one per line):", "")
|
| 42 |
|