forked from IntelLabs/fastRAG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_demo.py
66 lines (53 loc) · 1.75 KB
/
run_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import argparse
import os
import subprocess # nosec B404
import time
TASKS = {
"QA1": "qa_pipeline.yaml",
"QA2": "qa_plaid.yaml",
"QADIFF": "qa_diffusion_pipeline.yaml",
"SUMR": "summarization_pipeline.yaml",
}
SCREENS = {
"QA1": "webapp",
"QA2": "webapp",
"QADIFF": "webapp",
"SUMR": "webapp_summarization",
}
def run_service(cmd):
"""Starting a subprocess in the background"""
subprocess.Popen(f"{cmd} >/dev/null 2>&1 &", shell=True)
def get_pid(cmd):
output = subprocess.check_output(
f"ps aux | grep '{cmd}' | grep -v 'grep' | awk '{{print $2}}'", shell=True
)
return output.decode("utf-8").strip()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="fastRAG Demo")
parser.add_argument(
"-t",
"--task_config",
type=str,
default="QA1",
choices=list(TASKS.keys()),
help=f"The abbreviated name for the task configuraion. \n {TASKS} \n",
)
args = parser.parse_args()
path = os.getcwd()
# Create REST server
cmd = f"python -m fastrag.rest_api.application --config={path}/config/TASKCONFIGURATION"
cmd = cmd.replace("TASKCONFIGURATION", TASKS[args.task_config])
run_service(cmd)
# Create UI
os.environ["API_ENDPOINT"] = "http://localhost:8000"
cmd = f"python -m streamlit run {path}/fastrag/ui/SCREEN.py"
cmd = cmd.replace("SCREEN", SCREENS[args.task_config])
run_service(cmd)
# Sleep and wait for initialization, pids
print("Creating services...")
time.sleep(10)
s_pid = get_pid("fastrag.rest_api.application")
u_pid = get_pid("streamlit run")
print("\n")
print(f"Server on localhost:8000/docs PID={s_pid}")
print(f"UI on localhost:8501 PID={u_pid}")