Spaces:
Running
on
Zero
Running
on
Zero
jadechoghari
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,153 +1,161 @@
|
|
1 |
-
import os
|
2 |
-
import gradio as gr
|
3 |
-
from gradio_molecule3d import Molecule3D
|
4 |
-
import spaces
|
5 |
-
import subprocess
|
6 |
-
import glob
|
7 |
-
|
8 |
-
|
9 |
-
# directory to store cached outputs
|
10 |
-
CACHE_DIR = "gradio_cached_examples"
|
11 |
-
|
12 |
-
|
13 |
-
reps = [
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
# Ensure the cache directory exists
|
27 |
-
os.makedirs(CACHE_DIR, exist_ok=True)
|
28 |
-
|
29 |
-
# Define example files and precomputed outputs
|
30 |
-
example_fasta_files = [
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
]
|
42 |
-
|
43 |
-
# matching `.pdb` files in the `CACHE_DIR`
|
44 |
-
example_outputs = [
|
45 |
-
|
46 |
-
|
47 |
-
]
|
48 |
-
|
49 |
-
# must load cached outputs
|
50 |
-
def load_cached_example_outputs(fasta_file: str) -> str:
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
# handle example click
|
60 |
-
def on_example_click(fasta_file: str) -> str:
|
61 |
-
|
62 |
-
|
63 |
-
# run predictions
|
64 |
-
@spaces.GPU(duration=120)
|
65 |
-
def predict(data,
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
def run_prediction(input_file, accelerator, sampling_steps,
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
|
118 |
|
119 |
-
with gr.Blocks() as demo:
|
120 |
-
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
|
132 |
-
|
133 |
-
|
134 |
|
135 |
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
|
150 |
|
151 |
|
152 |
-
if __name__ == "__main__":
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import os
|
2 |
+
# import gradio as gr
|
3 |
+
# from gradio_molecule3d import Molecule3D
|
4 |
+
# import spaces
|
5 |
+
# import subprocess
|
6 |
+
# import glob
|
7 |
+
|
8 |
+
|
9 |
+
# # directory to store cached outputs
|
10 |
+
# CACHE_DIR = "gradio_cached_examples"
|
11 |
+
|
12 |
+
|
13 |
+
# reps = [
|
14 |
+
# {
|
15 |
+
# "model": 0,
|
16 |
+
# "chain": "",
|
17 |
+
# "resname": "",
|
18 |
+
# "style": "stick",
|
19 |
+
# "color": "whiteCarbon",
|
20 |
+
# "residue_range": "",
|
21 |
+
# "around": 0,
|
22 |
+
# "byres": False,
|
23 |
+
# "visible": False
|
24 |
+
# }
|
25 |
+
# ]
|
26 |
+
# # Ensure the cache directory exists
|
27 |
+
# os.makedirs(CACHE_DIR, exist_ok=True)
|
28 |
+
|
29 |
+
# # Define example files and precomputed outputs
|
30 |
+
# example_fasta_files = [
|
31 |
+
# f"cache_examples/boltz_0.fasta",
|
32 |
+
# f"cache_examples/Armadillo_6.fasta",
|
33 |
+
# f"cache_examples/Covid_3.fasta",
|
34 |
+
# f"cache_examples/Malaria_2.fasta",
|
35 |
+
# f"cache_examples/MITOCHONDRIAL_9.fasta",
|
36 |
+
# f"cache_examples/Monkeypox_4.fasta",
|
37 |
+
# f"cache_examples/Plasmodium_1.fasta",
|
38 |
+
# f"cache_examples/PROTOCADHERIN_8.fasta",
|
39 |
+
# f"cache_examples/Vault_5.fasta",
|
40 |
+
# f"cache_examples/Zipper_7.fasta",
|
41 |
+
# ]
|
42 |
+
|
43 |
+
# # matching `.pdb` files in the `CACHE_DIR`
|
44 |
+
# example_outputs = [
|
45 |
+
# os.path.join(CACHE_DIR, os.path.basename(fasta_file).replace(".fasta", ".pdb"))
|
46 |
+
# for fasta_file in example_fasta_files
|
47 |
+
# ]
|
48 |
+
|
49 |
+
# # must load cached outputs
|
50 |
+
# def load_cached_example_outputs(fasta_file: str) -> str:
|
51 |
+
# # Find the corresponding `.pdb` file
|
52 |
+
# pdb_file = os.path.basename(fasta_file).replace(".fasta", ".pdb")
|
53 |
+
# cached_pdb_path = os.path.join(CACHE_DIR, pdb_file)
|
54 |
+
# if os.path.exists(cached_pdb_path):
|
55 |
+
# return cached_pdb_path
|
56 |
+
# else:
|
57 |
+
# raise FileNotFoundError(f"Cached output not found for {pdb_file}")
|
58 |
+
|
59 |
+
# # handle example click
|
60 |
+
# def on_example_click(fasta_file: str) -> str:
|
61 |
+
# return load_cached_example_outputs(fasta_file)
|
62 |
+
|
63 |
+
# # run predictions
|
64 |
+
# @spaces.GPU(duration=120)
|
65 |
+
# def predict(data,
|
66 |
+
# accelerator="gpu", sampling_steps=50,
|
67 |
+
# diffusion_samples=1):
|
68 |
+
|
69 |
+
# print("Arguments passed to `predict` function:")
|
70 |
+
# print(f" data: {data}")
|
71 |
+
# print(f" accelerator: {accelerator}")
|
72 |
+
# print(f" sampling_steps: {sampling_steps}")
|
73 |
+
# print(f" diffusion_samples: {diffusion_samples}")
|
74 |
+
# # we construct the base command
|
75 |
+
# command = [
|
76 |
+
# "boltz", "predict",
|
77 |
+
# "--out_dir", "./",
|
78 |
+
# "--accelerator", accelerator,
|
79 |
+
# "--sampling_steps", str(sampling_steps),
|
80 |
+
# "--diffusion_samples", str(diffusion_samples),
|
81 |
+
# "--output_format", "pdb",
|
82 |
+
# ]
|
83 |
+
# command.extend(["--checkpoint", "./ckpt/boltz1.ckpt"])
|
84 |
+
# command.append(data)
|
85 |
+
# result = subprocess.run(command, capture_output=True, text=True)
|
86 |
+
# if result.returncode == 0:
|
87 |
+
# print("Prediction completed successfully...!")
|
88 |
+
# print(f"Output saved to: {out_dir}")
|
89 |
+
# else:
|
90 |
+
# print("Prediction failed :(")
|
91 |
+
# print("Error:", result.stderr)
|
92 |
+
|
93 |
+
# def run_prediction(input_file, accelerator, sampling_steps,
|
94 |
+
# diffusion_samples):
|
95 |
+
# data = input_file.name
|
96 |
+
# print("the data : ", data)
|
97 |
+
# predict(
|
98 |
+
# data=data,
|
99 |
+
# accelerator=accelerator,
|
100 |
+
# sampling_steps=sampling_steps,
|
101 |
+
# diffusion_samples=diffusion_samples
|
102 |
+
# )
|
103 |
+
|
104 |
+
# # search for the latest .pdb file in the predictions folder
|
105 |
+
# out_dir = "./"
|
106 |
+
# search_path = os.path.join(out_dir, "boltz_results*/predictions/**/*.pdb")
|
107 |
+
# pdb_files = glob.glob(search_path, recursive=True)
|
108 |
|
109 |
+
# if not pdb_files:
|
110 |
+
# print("No .pdb files found in the predictions folder.")
|
111 |
+
# return None
|
112 |
|
113 |
+
# # some manual logic
|
114 |
+
# # get the latest .pdb file based on modification time
|
115 |
+
# latest_pdb_file = max(pdb_files, key=os.path.getmtime)
|
116 |
+
# return latest_pdb_file
|
117 |
|
118 |
|
119 |
+
# with gr.Blocks() as demo:
|
120 |
+
# gr.Markdown("# 🔬 Boltz-1: Democratizing Biomolecular Interaction Modeling 🧬")
|
121 |
|
122 |
+
# with gr.Row():
|
123 |
+
# with gr.Column(scale=1):
|
124 |
+
# inp = gr.File(label="Upload a .fasta File", file_types=[".fasta"])
|
125 |
|
126 |
+
# with gr.Accordion("Advanced Settings", open=False):
|
127 |
+
# accelerator = gr.Radio(choices=["gpu", "cpu"], value="gpu", label="Accelerator")
|
128 |
+
# sampling_steps = gr.Slider(minimum=1, maximum=500, value=50, step=1, label="Sampling Steps")
|
129 |
+
# diffusion_samples = gr.Slider(minimum=1, maximum=10, value=1, step=1, label="Diffusion Samples")
|
130 |
+
# btn = gr.Button("Predict")
|
131 |
|
132 |
+
# with gr.Column(scale=3):
|
133 |
+
# out = Molecule3D(label="Generated Molecule", reps=reps)
|
134 |
|
135 |
|
136 |
|
137 |
+
# btn.click(
|
138 |
+
# run_prediction,
|
139 |
+
# inputs=[inp, accelerator, sampling_steps, diffusion_samples],
|
140 |
+
# outputs=out
|
141 |
+
# )
|
142 |
+
# gr.Examples(
|
143 |
+
# examples=[[fasta_file] for fasta_file in example_fasta_files],
|
144 |
+
# inputs=[inp],
|
145 |
+
# outputs=out,
|
146 |
+
# fn=lambda fasta_file: on_example_click(fasta_file),
|
147 |
+
# cache_examples=True
|
148 |
+
# )
|
149 |
|
150 |
|
151 |
|
152 |
+
# if __name__ == "__main__":
|
153 |
+
# demo.launch(share=True, debug=True)
|
154 |
+
|
155 |
+
import gradio as gr
|
156 |
+
|
157 |
+
def greet(name):
|
158 |
+
return "Hello " + name + "!!"
|
159 |
+
|
160 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
161 |
+
demo.launch()
|