-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
73 lines (49 loc) · 1.41 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
68
69
70
71
72
from flask import Flask, jsonify, request
import platform
import random
import sys
import os
linux = "tgpt \"__q__\" > __reply__"
CUR = []
def install_tgpt():
os.system("curl -sSL https://raw.githubusercontent.com/aandrew-me/tgpt/main/install | bash -s /usr/local/bin")
if not os.path.exists("/usr/local/bin/tgpt"):
install_tgpt()
def run_id():
global CUR
while True:
r = random.randint(999999,999999999999)
if r not in CUR:
CUR.append(r)
return r
def read_reply(id_):
f = open("." + str(id_), "r")
txt = f.read()
f.close()
os.remove("." + str(id_))
txt = txt.split("\n")
new = ""
n = 0
for e in txt:
if e != '':
new += e
else:
new += "\n"
return new[:-1]
def generate(q):
id_ = run_id()
os.system(linux.replace("__q__", q).replace("__reply__", "." + str(id_) ))
rep = read_reply(id_)
CUR.remove(id_)
rep = rep.replace("\n\u28fe", "")
for e in "Loading\u28fd Loading\u28fb Loading\u28bf Loading\u287f Loading\u28df Loading\u28ef Loading\u28f7 Loading\u28fe Loading\n".split(" "):
rep = rep.replace(e, "")
while rep.startswith(" "):
rep = rep[1:]
return rep
app = Flask(__name__)
@app.route('/generate')
def gen():
data = generate(request.headers['prompt'].replace('"', "'"))
return jsonify({'return': data})
app.run()