Spaces:
Sleeping
Sleeping
Commit ·
73ac8c4
1
Parent(s): 7795f1e
other version
Browse files- README.md +2 -2
- app.py +55 -80
- requirements.txt +12 -4
README.md
CHANGED
|
@@ -3,9 +3,9 @@ title: BoltzGen
|
|
| 3 |
emoji: 📈
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: indigo
|
| 6 |
-
sdk:
|
|
|
|
| 7 |
pinned: true
|
| 8 |
-
app_port: 7680
|
| 9 |
---
|
| 10 |
|
| 11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 3 |
emoji: 📈
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: indigo
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 6.3.0
|
| 8 |
pinned: true
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -1,90 +1,65 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
#import torch
|
| 3 |
-
from pathlib import Path
|
| 4 |
import os
|
| 5 |
-
import
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
sys.path.append("/home/user/app/BoltzGen")
|
| 9 |
-
|
| 10 |
-
from boltzgen import boltzgen
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
def
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# Generate designs
|
| 24 |
-
designs = generator.generate(
|
| 25 |
-
prompt=sequence_prompt,
|
| 26 |
-
num_designs=num_designs,
|
| 27 |
-
temperature=temperature,
|
| 28 |
-
num_inference_steps=50
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
-
# Format results for display
|
| 32 |
-
results = []
|
| 33 |
-
for i, design in enumerate(designs):
|
| 34 |
-
result = f"**Design {i+1}:**\n```fasta\n{design.sequence}\n```\n"
|
| 35 |
-
result += f"**Score:** {design.score:.3f}\n"
|
| 36 |
-
result += f"**Length:** {len(design.sequence)}\n"
|
| 37 |
-
if hasattr(design, 'pdb') and design.pdb:
|
| 38 |
-
result += f"[PDB structure available]\n"
|
| 39 |
-
results.append(result)
|
| 40 |
-
|
| 41 |
-
return "\n---\n".join(results)
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
except Exception as e:
|
| 44 |
-
return f"
|
| 45 |
|
| 46 |
-
# Gradio
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
gr.
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
lines=3,
|
| 61 |
-
value="Design a stable TIM barrel enzyme scaffold"
|
| 62 |
-
)
|
| 63 |
-
num_designs = gr.Slider(1, 8, value=4, label="Number of Designs")
|
| 64 |
-
temperature = gr.Slider(0.1, 2.0, value=0.8, label="Temperature (Creativity)")
|
| 65 |
-
generate_btn = gr.Button("Generate Proteins", variant="primary")
|
| 66 |
-
|
| 67 |
-
with gr.Column(scale=1):
|
| 68 |
-
output = gr.Markdown(label="Generated Designs")
|
| 69 |
-
|
| 70 |
-
generate_btn.click(
|
| 71 |
-
fn=generate_protein,
|
| 72 |
-
inputs=[prompt, num_designs, temperature],
|
| 73 |
-
outputs=output
|
| 74 |
-
)
|
| 75 |
-
|
| 76 |
-
gr.Markdown("### Examples")
|
| 77 |
-
gr.Examples(
|
| 78 |
-
examples=[
|
| 79 |
-
["Design a stable alpha-helical bundle with 100 residues"],
|
| 80 |
-
["Create a beta-barrel protein for membrane insertion"],
|
| 81 |
-
["Generate a de novo enzyme scaffold with catalytic triad"]
|
| 82 |
-
],
|
| 83 |
-
inputs=[prompt]
|
| 84 |
-
)
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
if __name__ == "__main__":
|
| 89 |
-
demo
|
| 90 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
import yaml
|
| 5 |
+
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Example YAML from README style (customize as needed)
|
| 8 |
+
EXAMPLE_YAML = """
|
| 9 |
+
entities:
|
| 10 |
+
- protein:
|
| 11 |
+
id: B
|
| 12 |
+
sequence: 80..140
|
| 13 |
+
- file:
|
| 14 |
+
path: 6m1u.cif # Upload your target PDB/CIF
|
| 15 |
+
include:
|
| 16 |
+
- chain:
|
| 17 |
+
id: A
|
| 18 |
+
"""
|
| 19 |
|
| 20 |
+
def run_boltzgen(yaml_content, protocol="protein-anything", num_designs=10, budget=2, output_dir="./output"):
|
| 21 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 22 |
+
|
| 23 |
+
# Write YAML spec
|
| 24 |
+
yaml_path = Path(output_dir) / "design.yaml"
|
| 25 |
+
with open(yaml_path, "w") as f:
|
| 26 |
+
yaml.dump(yaml.safe_load(yaml_content), f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# Run BoltzGen (models auto-download to ~/.cache/huggingface)
|
| 29 |
+
cmd = [
|
| 30 |
+
"boltzgen", "run", str(yaml_path),
|
| 31 |
+
"--output", output_dir,
|
| 32 |
+
"--protocol", protocol,
|
| 33 |
+
"--num_designs", str(num_designs),
|
| 34 |
+
"--budget", str(budget),
|
| 35 |
+
"--cache", "/tmp/cache" # Persistent cache in Space
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
try:
|
| 39 |
+
result = subprocess.run(cmd, capture_output=True, text=True, cwd=output_dir)
|
| 40 |
+
if result.returncode == 0:
|
| 41 |
+
return f"Success! Designs saved to {output_dir}/final_ranked_designs/. Logs:\n{result.stdout}"
|
| 42 |
+
else:
|
| 43 |
+
return f"Error:\n{result.stderr}"
|
| 44 |
except Exception as e:
|
| 45 |
+
return f"Failed: {str(e)}"
|
| 46 |
|
| 47 |
+
# Gradio interface
|
| 48 |
+
with gr.Blocks(title="BoltzGen on HF Spaces") as demo:
|
| 49 |
+
gr.Markdown("# BoltzGen: Protein Binder Design\nRun designs directly in-browser with GPU.")
|
| 50 |
+
|
| 51 |
+
with gr.Row():
|
| 52 |
+
yaml_input = gr.Textbox(EXAMPLE_YAML, label="Design YAML", lines=15)
|
| 53 |
+
protocol = gr.Dropdown(["protein-anything", "peptide-anything", "nanobody-anything"], value="protein-anything", label="Protocol")
|
| 54 |
+
|
| 55 |
+
with gr.Row():
|
| 56 |
+
num_designs = gr.Slider(10, 1000, value=50, label="Num Designs (start small)")
|
| 57 |
+
budget = gr.Slider(1, 20, value=2, label="Final Budget")
|
| 58 |
+
|
| 59 |
+
run_btn = gr.Button("Run BoltzGen", variant="primary")
|
| 60 |
+
output = gr.Textbox(label="Output Logs & Results", lines=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
run_btn.click(run_boltzgen, inputs=[yaml_input, protocol, num_designs, budget], outputs=output)
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
+
demo.launch()
|
|
|
requirements.txt
CHANGED
|
@@ -1,6 +1,14 @@
|
|
| 1 |
-
torch torchvision torchaudio --index-url https://download.pytorch.org/whl/
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
omegaconf
|
|
|
|
|
|
|
| 6 |
einops
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu124
|
| 2 |
+
boltzgen
|
| 3 |
+
huggingface_hub
|
| 4 |
+
pyyaml
|
| 5 |
omegaconf
|
| 6 |
+
hydra-core
|
| 7 |
+
lightning
|
| 8 |
einops
|
| 9 |
+
se3diffusers
|
| 10 |
+
e3nn==0.5.3
|
| 11 |
+
diffusers
|
| 12 |
+
transformers
|
| 13 |
+
accelerate
|
| 14 |
+
|