AlexiaMoller commited on
Commit
73ac8c4
·
1 Parent(s): 7795f1e

other version

Browse files
Files changed (3) hide show
  1. README.md +2 -2
  2. app.py +55 -80
  3. requirements.txt +12 -4
README.md CHANGED
@@ -3,9 +3,9 @@ title: BoltzGen
3
  emoji: 📈
4
  colorFrom: red
5
  colorTo: indigo
6
- sdk: docker
 
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 sys
6
-
7
- if "/home/user/app/BoltzGen" not in sys.path:
8
- sys.path.append("/home/user/app/BoltzGen")
9
-
10
- from boltzgen import boltzgen
11
 
12
- # Use HF cache dir from env
13
- CACHE_DIR = os.environ.get("HF_HOME", "/cache")
 
 
 
 
 
 
 
 
 
 
14
 
15
- def generate_protein(sequence_prompt, num_designs=4, temperature=0.8):
16
- """
17
- Generate protein designs using BoltzGen from a text prompt.
18
- """
19
- try:
20
- # Initialize BoltzGen generator (assumes models loaded from HF cache)
21
- generator = boltzgen.Generator(model_dir=CACHE_DIR)
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"Error generating design: {str(e)}"
45
 
46
- # Gradio Interface
47
- def create_demo():
48
- with gr.Blocks(
49
- title="BoltzGen Protein Design",
50
- theme=gr.themes.Soft()
51
- ) as demo:
52
- gr.Markdown("# 🧬 BoltzGen Protein Generator")
53
- gr.Markdown("Generate novel protein sequences from natural language prompts using BoltzGen.")
54
-
55
- with gr.Row():
56
- with gr.Column(scale=1):
57
- prompt = gr.Textbox(
58
- label="Protein Design Prompt",
59
- placeholder="Design a stable alpha-helical bundle with 100 residues...",
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
- return demo
87
 
88
  if __name__ == "__main__":
89
- demo = create_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/cu121
2
- gradio
3
- transformers
4
- accelerate
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
+