PhDFlo commited on
Commit
b327bba
·
1 Parent(s): 8839f2e

modifs main

Browse files
Files changed (2) hide show
  1. app.py +46 -6
  2. modal_app.py +0 -4
app.py CHANGED
@@ -1,8 +1,20 @@
1
- import gradio as gr
2
- from modal_app import app, square
 
 
 
3
 
4
- def compute_square(x):
5
- """Compute the square of a number.
 
 
 
 
 
 
 
 
 
6
 
7
  Args:
8
  x (float | int): The number to square.
@@ -11,11 +23,39 @@ def compute_square(x):
11
  float: The square of the input number.
12
  """
13
  with app.run():
14
- return square.remote(float(x))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  # Create a standard Gradio interface
17
  demo = gr.Interface(
18
- fn=compute_square,
19
  inputs=gr.Number(label="Enter a number"),
20
  outputs=gr.Number(label="Square of the number"),
21
  title="Compute Square using Modal",
 
1
+ from pathlib import Path
2
+ from typing import Optional
3
+ from uuid import uuid4
4
+ import hashlib
5
+ import json
6
 
7
+ import gradio as gr
8
+ from modal_app import app, chai1_inference, download_inference_dependencies, here,
9
+
10
+ def compute_Chai1(
11
+ force_redownload: bool = False,
12
+ fasta_file: Optional[str] = None,
13
+ inference_config_file: Optional[str] = None,
14
+ output_dir: Optional[str] = None,
15
+ run_id: Optional[str] = None,
16
+ ):
17
+ """Compute a Chai1 simulation.
18
 
19
  Args:
20
  x (float | int): The number to square.
 
23
  float: The square of the input number.
24
  """
25
  with app.run():
26
+
27
+ print("🧬 checking inference dependencies")
28
+ download_inference_dependencies.remote(force=force_redownload)
29
+
30
+ if fasta_file is None:
31
+ fasta_file = here / "inputs" / "chai1_default_input.fasta"
32
+ print(f"🧬 running Chai inference on {fasta_file}")
33
+ fasta_content = Path(fasta_file).read_text()
34
+
35
+ if inference_config_file is None:
36
+ inference_config_file = here / "inputs" / "chai1_quick_inference.json"
37
+ print(f"🧬 loading Chai inference config from {inference_config_file}")
38
+ inference_config = json.loads(Path(inference_config_file).read_text())
39
+
40
+ if run_id is None:
41
+ run_id = hashlib.sha256(uuid4().bytes).hexdigest()[:8] # short id
42
+ print(f"🧬 running inference with {run_id=}")
43
+
44
+ results = chai1_inference.remote(fasta_content, inference_config, run_id)
45
+
46
+ if output_dir is None:
47
+ output_dir = Path("./results")
48
+ output_dir.mkdir(parents=True, exist_ok=True)
49
+
50
+ print(f"🧬 saving results to disk locally in {output_dir}")
51
+ for ii, (scores, cif) in enumerate(results):
52
+ (Path(output_dir) / f"{run_id}-scores.model_idx_{ii}.npz").write_bytes(scores)
53
+ (Path(output_dir) / f"{run_id}-preds.model_idx_{ii}.cif").write_text(cif)
54
+
55
 
56
  # Create a standard Gradio interface
57
  demo = gr.Interface(
58
+ fn=compute_Chai1,
59
  inputs=gr.Number(label="Enter a number"),
60
  outputs=gr.Number(label="Square of the number"),
61
  title="Compute Square using Modal",
modal_app.py CHANGED
@@ -1,9 +1,5 @@
1
  # Import necessary libraries
2
- import hashlib
3
- import json
4
  from pathlib import Path
5
- from typing import Optional
6
- from uuid import uuid4
7
 
8
  import modal
9
 
 
1
  # Import necessary libraries
 
 
2
  from pathlib import Path
 
 
3
 
4
  import modal
5