LTEnjoy commited on
Commit
3537dc0
·
verified ·
1 Parent(s): 2470b12

Update run.py

Browse files
Files changed (1) hide show
  1. run.py +47 -49
run.py CHANGED
@@ -1,49 +1,47 @@
1
- import sys
2
- root_dir = __file__.rsplit("/", 1)[0]
3
- if root_dir not in sys.path:
4
- sys.path.append(root_dir)
5
-
6
- import gradio as gr
7
- import asyncio
8
- import os
9
-
10
- from demo.modules.search import build_search_module
11
- from demo.modules.compute_score import build_score_computation
12
- from demo.modules.tmalign import build_TMalign
13
-
14
-
15
- # Build demo
16
- with gr.Blocks() as demo:
17
- build_search_module()
18
- build_score_computation()
19
- build_TMalign()
20
-
21
-
22
- # Asynchronously download the required index files
23
- async def run_cmd(cmd):
24
- process = await asyncio.create_subprocess_shell(
25
- cmd,
26
- stdout=asyncio.subprocess.PIPE,
27
- stderr=asyncio.subprocess.PIPE
28
- )
29
- stdout, stderr = await process.communicate()
30
- print(f'[{cmd!r} exited with {process.returncode}]')
31
- if stdout:
32
- print(f'[stdout]\n{stdout.decode()}')
33
- if stderr:
34
- print(f'[stderr]\n{stderr.decode()}')
35
-
36
-
37
- async def download_faiss_index():
38
- await asyncio.gather(
39
- run_cmd("echo Hello World!"),
40
- run_cmd('huggingface-cli download westlake-repl/ProTrek-faiss-index --repo-type dataset --local-dir /data/ProTrek-faiss-index --include "ProTrek_650M_UniRef50/UniRef50/*"'),
41
- )
42
-
43
-
44
- if __name__ == '__main__':
45
- # Run the async function to download the index files
46
- asyncio.run(download_faiss_index())
47
-
48
- # Run the demo
49
- demo.launch()
 
1
+ import sys
2
+ root_dir = __file__.rsplit("/", 1)[0]
3
+ if root_dir not in sys.path:
4
+ sys.path.append(root_dir)
5
+
6
+ import gradio as gr
7
+ import asyncio
8
+ import os
9
+
10
+ # from demo.modules.search import build_search_module
11
+ # from demo.modules.compute_score import build_score_computation
12
+ # from demo.modules.tmalign import build_TMalign
13
+
14
+
15
+ # Build demo
16
+ with gr.Blocks() as demo:
17
+ # build_search_module()
18
+ # build_score_computation()
19
+ # build_TMalign()
20
+
21
+ import gradio as gr
22
+ import subprocess
23
+
24
+
25
+ def run_command(cmd: str) -> str:
26
+ p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
27
+ stdout, stderr = p.communicate()
28
+
29
+ if stdout:
30
+ return f"[Output]\n{stdout.decode()}"
31
+ if stderr:
32
+ return f"[Error]\n{stderr.decode()}"
33
+
34
+
35
+ # Build the block for command line interface
36
+ gr.Markdown(f"# Input your command and click to run")
37
+ with gr.Column():
38
+ cmd = gr.Textbox(label="Input your command", value="echo 'Hello, World!'")
39
+ btn = gr.Button(value="Run")
40
+ output = gr.TextArea(label="Output", interactive=False)
41
+
42
+ btn.click(run_command, inputs=[cmd], outputs=[output])
43
+
44
+
45
+ if __name__ == '__main__':
46
+ # Run the demo
47
+ demo.launch()