-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.py
67 lines (59 loc) · 1.9 KB
/
main.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
67
# This wrapper automatically loads the API
import sys, select, time, os, subprocess, sys
from dotenv import load_dotenv
load_dotenv()
if "API_SECRET" not in os.environ:
print("You must set an API_SECRET using the Secrets tool", file=sys.stderr)
elif "OPENAI_API_KEY" not in os.environ:
print("You must set an OPENAI_API_KEY using the Secrets tool", file=sys.stderr)
else:
print("== OPENAI + REPLIT CUSTOM BOT==")
print("You have five seconds to select an option")
print()
print(
"1: Train Model\n2: Talk to your Bot\n3: Run API server (Default)\n> ", end=""
)
i, o, e = select.select([sys.stdin], [], [], 10)
print()
if i:
choice = sys.stdin.readline().strip()
time.sleep(0.5)
os.system("clear")
if choice == "1":
print("BOT TRAINING MODE")
import process
process.train()
elif choice == "2":
print("BOT CONVERSATION MODE")
import process
process.runPrompt()
else:
print("Booting into API Server…")
time.sleep(1)
os.system("clear")
print("BOT API SERVER RUNNING")
p = subprocess.Popen(
[sys.executable, "server.py"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
while True:
line = p.stdout.readline()
if not line:
break
else:
time.sleep(0.5)
os.system("clear")
print("Booting into API Server…")
time.sleep(1)
os.system("clear")
print("BOT API SERVER RUNNING")
p = subprocess.Popen(
[sys.executable, "server.py"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
while True:
line = p.stdout.readline()
if not line:
break