LTEnjoy's picture
Update run.py
7ec7132 verified
raw
history blame
1.25 kB
import sys
root_dir = __file__.rsplit("/", 1)[0]
if root_dir not in sys.path:
sys.path.append(root_dir)
import gradio as gr
import asyncio
import os
from demo.modules.search import build_search_module
from demo.modules.compute_score import build_score_computation
from demo.modules.tmalign import build_TMalign
# Build demo
with gr.Blocks() as demo:
build_search_module()
build_score_computation()
build_TMalign()
import gradio as gr
import subprocess
def run_command(cmd: str) -> str:
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if stdout:
return f"[Output]\n{stdout.decode()}"
if stderr:
return f"[Error]\n{stderr.decode()}"
# Build the block for command line interface
gr.Markdown(f"# Input your command and click to run")
with gr.Column():
cmd = gr.Textbox(label="Input your command", value="echo 'Hello, World!'")
btn = gr.Button(value="Run")
output = gr.TextArea(label="Output", interactive=False)
btn.click(run_command, inputs=[cmd], outputs=[output])
if __name__ == '__main__':
# Run the demo
demo.launch()