Spaces:
Running
on
Zero
Running
on
Zero
feiyang-cai
commited on
Commit
·
63859b8
1
Parent(s):
a7655fc
update
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import HfApi, get_collection, list_collections
|
3 |
-
from utils import MolecularPropertyPredictionModel,
|
4 |
import pandas as pd
|
5 |
import os
|
6 |
|
@@ -12,22 +12,26 @@ def get_models():
|
|
12 |
if item.item_type == "model":
|
13 |
item_name = item.item_id.split("/")[-1]
|
14 |
models[item_name] = item.item_id
|
15 |
-
assert item_name in
|
16 |
assert item_name in dataset_descriptions, f"{item_name} is not in the dataset_descriptions"
|
17 |
|
18 |
return models
|
19 |
|
20 |
candidate_models = get_models()
|
21 |
-
properties =
|
|
|
22 |
model = MolecularPropertyPredictionModel(candidate_models)
|
23 |
|
24 |
def get_description(property_name):
|
25 |
-
|
|
|
26 |
|
27 |
def predict_single_label(smiles, property_name):
|
|
|
|
|
28 |
try:
|
29 |
-
adapter_id = candidate_models[
|
30 |
-
info = model.swith_adapter(
|
31 |
|
32 |
running_status = None
|
33 |
if info == "keep":
|
@@ -45,7 +49,7 @@ def predict_single_label(smiles, property_name):
|
|
45 |
return "NA", running_status
|
46 |
|
47 |
#prediction = model.predict(smiles, property_name, adapter_id)
|
48 |
-
prediction = model.predict_single_smiles(smiles,
|
49 |
if prediction is None:
|
50 |
return "NA", "Invalid SMILES string"
|
51 |
|
@@ -60,9 +64,10 @@ def predict_single_label(smiles, property_name):
|
|
60 |
return prediction, "Prediction is done"
|
61 |
|
62 |
def predict_file(file, property_name):
|
|
|
63 |
try:
|
64 |
-
adapter_id = candidate_models[
|
65 |
-
info = model.swith_adapter(
|
66 |
|
67 |
running_status = None
|
68 |
if info == "keep":
|
@@ -81,7 +86,7 @@ def predict_file(file, property_name):
|
|
81 |
|
82 |
df = pd.read_csv(file)
|
83 |
# we have already checked the file contains the "smiles" column
|
84 |
-
df = model.predict_file(df,
|
85 |
# we should save this file to the disk to be downloaded
|
86 |
# rename the file to have "_prediction" suffix
|
87 |
prediction_file = file.replace(".csv", "_prediction.csv") if file.endswith(".csv") else file.replace(".smi", "_prediction.csv")
|
@@ -157,10 +162,12 @@ def build_inference():
|
|
157 |
with gr.Blocks() as demo:
|
158 |
# first row - Dropdown input
|
159 |
#with gr.Row():
|
160 |
-
|
|
|
|
|
161 |
description_box = gr.Textbox(label="Property description", lines=5,
|
162 |
interactive=False,
|
163 |
-
value=dataset_descriptions[
|
164 |
# third row - Textbox input and prediction label
|
165 |
with gr.Row(equal_height=True):
|
166 |
with gr.Column():
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import HfApi, get_collection, list_collections
|
3 |
+
from utils import MolecularPropertyPredictionModel, dataset_task_types, dataset_descriptions, dataset_property_names, dataset_property_names_to_dataset
|
4 |
import pandas as pd
|
5 |
import os
|
6 |
|
|
|
12 |
if item.item_type == "model":
|
13 |
item_name = item.item_id.split("/")[-1]
|
14 |
models[item_name] = item.item_id
|
15 |
+
assert item_name in dataset_task_types, f"{item_name} is not in the task_types"
|
16 |
assert item_name in dataset_descriptions, f"{item_name} is not in the dataset_descriptions"
|
17 |
|
18 |
return models
|
19 |
|
20 |
candidate_models = get_models()
|
21 |
+
properties = [dataset_property_names[item] for item in candidate_models.keys()]
|
22 |
+
property_names = list(candidate_models.keys())
|
23 |
model = MolecularPropertyPredictionModel(candidate_models)
|
24 |
|
25 |
def get_description(property_name):
|
26 |
+
property_id = dataset_property_names_to_dataset[property_name]
|
27 |
+
return dataset_descriptions[property_id]
|
28 |
|
29 |
def predict_single_label(smiles, property_name):
|
30 |
+
property_id = dataset_property_names_to_dataset[property_name]
|
31 |
+
|
32 |
try:
|
33 |
+
adapter_id = candidate_models[property_id]
|
34 |
+
info = model.swith_adapter(property_id, adapter_id)
|
35 |
|
36 |
running_status = None
|
37 |
if info == "keep":
|
|
|
49 |
return "NA", running_status
|
50 |
|
51 |
#prediction = model.predict(smiles, property_name, adapter_id)
|
52 |
+
prediction = model.predict_single_smiles(smiles, dataset_task_types[property_id])
|
53 |
if prediction is None:
|
54 |
return "NA", "Invalid SMILES string"
|
55 |
|
|
|
64 |
return prediction, "Prediction is done"
|
65 |
|
66 |
def predict_file(file, property_name):
|
67 |
+
property_id = dataset_property_names_to_dataset[property_name]
|
68 |
try:
|
69 |
+
adapter_id = candidate_models[property_id]
|
70 |
+
info = model.swith_adapter(property_id, adapter_id)
|
71 |
|
72 |
running_status = None
|
73 |
if info == "keep":
|
|
|
86 |
|
87 |
df = pd.read_csv(file)
|
88 |
# we have already checked the file contains the "smiles" column
|
89 |
+
df = model.predict_file(df, dataset_task_types[property_id])
|
90 |
# we should save this file to the disk to be downloaded
|
91 |
# rename the file to have "_prediction" suffix
|
92 |
prediction_file = file.replace(".csv", "_prediction.csv") if file.endswith(".csv") else file.replace(".smi", "_prediction.csv")
|
|
|
162 |
with gr.Blocks() as demo:
|
163 |
# first row - Dropdown input
|
164 |
#with gr.Row():
|
165 |
+
print(property_names[0].lower())
|
166 |
+
print(properties)
|
167 |
+
dropdown = gr.Dropdown(properties, label="Property", value=dataset_property_names[property_names[0].lower()])
|
168 |
description_box = gr.Textbox(label="Property description", lines=5,
|
169 |
interactive=False,
|
170 |
+
value=dataset_descriptions[property_names[0].lower()])
|
171 |
# third row - Textbox input and prediction label
|
172 |
with gr.Row(equal_height=True):
|
173 |
with gr.Column():
|