Spaces:
Sleeping
Sleeping
testing gradio app.py
Browse files- app.py +30 -35
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,15 +1,6 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Minimal Hugging Face Space sanity-check app.
|
| 3 |
-
|
| 4 |
-
Purpose:
|
| 5 |
-
- Verify imports from applications/
|
| 6 |
-
- Verify Hugging Face model downloads
|
| 7 |
-
- Verify predictors run end-to-end
|
| 8 |
-
"""
|
| 9 |
-
|
| 10 |
import os
|
|
|
|
| 11 |
|
| 12 |
-
# Silence HF noise (optional but nice)
|
| 13 |
os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "1"
|
| 14 |
os.environ["HF_HUB_DISABLE_TELEMETRY"] = "1"
|
| 15 |
|
|
@@ -18,45 +9,49 @@ from applications.molecule_generator.main import run as run_molecule_generator
|
|
| 18 |
from core.config import EvolutionConfig
|
| 19 |
|
| 20 |
|
| 21 |
-
def
|
| 22 |
-
print("=== Testing Pure Predictor ===")
|
| 23 |
config = {
|
| 24 |
"mode": "1",
|
| 25 |
-
"smiles":
|
| 26 |
}
|
| 27 |
-
|
| 28 |
-
result = run_pure_predictor(config)
|
| 29 |
-
|
| 30 |
-
print("Pure predictor output:")
|
| 31 |
-
for k, v in result.items():
|
| 32 |
-
print(f" {k}: {v}")
|
| 33 |
-
|
| 34 |
-
print("β Pure predictor OK\n")
|
| 35 |
|
| 36 |
|
| 37 |
-
def
|
| 38 |
-
print("=== Testing Molecule Generator ===")
|
| 39 |
-
|
| 40 |
config = EvolutionConfig(
|
| 41 |
-
target_cn=
|
| 42 |
-
generations=
|
| 43 |
-
population_size=
|
| 44 |
minimize_ysi=False,
|
| 45 |
maximize_cn=False,
|
| 46 |
)
|
| 47 |
|
| 48 |
final_df, pareto_df = run_molecule_generator(config)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
print("Pareto front shape:", pareto_df.shape)
|
| 52 |
|
| 53 |
-
print("β Molecule generator OK\n")
|
| 54 |
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
|
|
|
|
| 4 |
os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "1"
|
| 5 |
os.environ["HF_HUB_DISABLE_TELEMETRY"] = "1"
|
| 6 |
|
|
|
|
| 9 |
from core.config import EvolutionConfig
|
| 10 |
|
| 11 |
|
| 12 |
+
def pure_predict(smiles):
|
|
|
|
| 13 |
config = {
|
| 14 |
"mode": "1",
|
| 15 |
+
"smiles": smiles,
|
| 16 |
}
|
| 17 |
+
return run_pure_predictor(config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
+
def generate_molecules(target_cn, generations, population_size):
|
|
|
|
|
|
|
| 21 |
config = EvolutionConfig(
|
| 22 |
+
target_cn=target_cn,
|
| 23 |
+
generations=generations,
|
| 24 |
+
population_size=population_size,
|
| 25 |
minimize_ysi=False,
|
| 26 |
maximize_cn=False,
|
| 27 |
)
|
| 28 |
|
| 29 |
final_df, pareto_df = run_molecule_generator(config)
|
| 30 |
|
| 31 |
+
return final_df, pareto_df
|
|
|
|
| 32 |
|
|
|
|
| 33 |
|
| 34 |
+
with gr.Blocks(title="Biofuel Optimiser β Generator Debug UI") as demo:
|
| 35 |
+
gr.Markdown("# π§ͺ Molecule Generator Sanity Check")
|
| 36 |
|
| 37 |
+
with gr.Tab("Pure Predictor"):
|
| 38 |
+
smiles = gr.Textbox(label="SMILES", value="CCC")
|
| 39 |
+
out_json = gr.JSON()
|
| 40 |
+
gr.Button("Predict").click(pure_predict, smiles, out_json)
|
| 41 |
+
|
| 42 |
+
with gr.Tab("Molecule Generator"):
|
| 43 |
+
target_cn = gr.Number(label="Target CN", value=55)
|
| 44 |
+
generations = gr.Slider(1, 5, value=1, step=1)
|
| 45 |
+
pop_size = gr.Slider(10, 200, value=50, step=10)
|
| 46 |
|
| 47 |
+
out_final = gr.Dataframe(label="Final Population")
|
| 48 |
+
out_pareto = gr.Dataframe(label="Pareto Front")
|
| 49 |
|
| 50 |
+
gr.Button("Generate").click(
|
| 51 |
+
generate_molecules,
|
| 52 |
+
inputs=[target_cn, generations, pop_size],
|
| 53 |
+
outputs=[out_final, out_pareto],
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
demo.launch()
|
requirements.txt
CHANGED
|
@@ -14,4 +14,5 @@ crem==0.2.16
|
|
| 14 |
joblib==1.5.2
|
| 15 |
tqdm==4.67.1
|
| 16 |
huggingface_hub==1.2.1
|
| 17 |
-
pytest==9.0.2
|
|
|
|
|
|
| 14 |
joblib==1.5.2
|
| 15 |
tqdm==4.67.1
|
| 16 |
huggingface_hub==1.2.1
|
| 17 |
+
pytest==9.0.2
|
| 18 |
+
gradio==3.37.1
|