Update app.py
Browse files
app.py
CHANGED
@@ -90,7 +90,7 @@ imgq= Queue()
|
|
90 |
|
91 |
def makeqchat():
|
92 |
|
93 |
-
while chatq.qsize()<
|
94 |
print("appending in chat queue")
|
95 |
options = ChromeOptions()
|
96 |
options.add_argument('--no-sandbox')
|
@@ -104,7 +104,7 @@ def makeqchat():
|
|
104 |
|
105 |
def makeqimg():
|
106 |
|
107 |
-
while imgq.qsize()<
|
108 |
print("appending in img queue")
|
109 |
options = ChromeOptions()
|
110 |
options.add_argument('--no-sandbox')
|
@@ -121,10 +121,22 @@ def makeqimg():
|
|
121 |
|
122 |
|
123 |
@app.post("/")
|
124 |
-
async def get_answer(
|
|
|
125 |
|
126 |
-
text =
|
127 |
-
host=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
# N = 20
|
130 |
# res = ''.join(random.choices(string.ascii_uppercase +
|
@@ -137,7 +149,7 @@ async def get_answer(q: Query ):
|
|
137 |
# t = threading.Thread(target=do_ML, args=(id,text,host,0))
|
138 |
# t.start()
|
139 |
|
140 |
-
res= do_ML(id,text,host,0)
|
141 |
|
142 |
|
143 |
dict={"ChatGPT":res}
|
@@ -151,7 +163,8 @@ async def get_answer(q: Query ):
|
|
151 |
|
152 |
|
153 |
|
154 |
-
def do_ML(id:str,text:str,host:str, trycount:int):
|
|
|
155 |
# options = ChromeOptions()
|
156 |
# options.add_argument('--no-sandbox')
|
157 |
# options.add_argument('-headless')
|
@@ -178,7 +191,22 @@ def do_ML(id:str,text:str,host:str, trycount:int):
|
|
178 |
t = threading.Thread(target=makeqchat)
|
179 |
t.start()
|
180 |
time.sleep(0.5)
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
textarea = driver.find_element(By.CSS_SELECTOR, "textarea")
|
184 |
textarea.send_keys(text)
|
@@ -195,24 +223,19 @@ def do_ML(id:str,text:str,host:str, trycount:int):
|
|
195 |
data=data={"id":id,"result":"","status":"Error"}
|
196 |
x= requests.post(host,data= data)
|
197 |
return
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
|
|
|
|
|
|
205 |
continue
|
206 |
|
207 |
-
|
208 |
-
# if value==prev:
|
209 |
-
# data={"id":id,"result":value,"status":"Generated"}
|
210 |
-
|
211 |
-
# driver.delete_all_cookies()
|
212 |
-
# driver.quit()
|
213 |
-
# requests.post(host, data=data)
|
214 |
-
# break
|
215 |
-
# prev= value
|
216 |
|
217 |
driver.delete_all_cookies()
|
218 |
driver.quit()
|
|
|
90 |
|
91 |
def makeqchat():
|
92 |
|
93 |
+
while chatq.qsize()<2:
|
94 |
print("appending in chat queue")
|
95 |
options = ChromeOptions()
|
96 |
options.add_argument('--no-sandbox')
|
|
|
104 |
|
105 |
def makeqimg():
|
106 |
|
107 |
+
while imgq.qsize()<2:
|
108 |
print("appending in img queue")
|
109 |
options = ChromeOptions()
|
110 |
options.add_argument('--no-sandbox')
|
|
|
121 |
|
122 |
|
123 |
@app.post("/")
|
124 |
+
async def get_answer(request: Request ):
|
125 |
+
data = await request.json()
|
126 |
|
127 |
+
text = data['text']
|
128 |
+
host= ''
|
129 |
+
|
130 |
+
temperature=-1
|
131 |
+
|
132 |
+
try:
|
133 |
+
temperature= data['temperature']
|
134 |
+
temperature= float(temperature)
|
135 |
+
temperature= round(temperature,1)
|
136 |
+
|
137 |
+
except:
|
138 |
+
print("No temperature")
|
139 |
+
|
140 |
|
141 |
# N = 20
|
142 |
# res = ''.join(random.choices(string.ascii_uppercase +
|
|
|
149 |
# t = threading.Thread(target=do_ML, args=(id,text,host,0))
|
150 |
# t.start()
|
151 |
|
152 |
+
res= do_ML(id,text,host,0,temperature)
|
153 |
|
154 |
|
155 |
dict={"ChatGPT":res}
|
|
|
163 |
|
164 |
|
165 |
|
166 |
+
def do_ML(id:str,text:str,host:str, trycount:int,temperature:float):
|
167 |
+
|
168 |
# options = ChromeOptions()
|
169 |
# options.add_argument('--no-sandbox')
|
170 |
# options.add_argument('-headless')
|
|
|
191 |
t = threading.Thread(target=makeqchat)
|
192 |
t.start()
|
193 |
time.sleep(0.5)
|
194 |
+
|
195 |
+
if temperature>=0 and temperature<=2:
|
196 |
+
try:
|
197 |
+
print("setting temperature ",temperature)
|
198 |
+
setting_button = driver.find_element(By.ID, "openSettings")
|
199 |
+
setting_button.click()
|
200 |
+
|
201 |
+
input_element = driver.find_element(By.CLASS_NAME,"styled-slider")
|
202 |
+
new_value = temperature
|
203 |
+
driver.execute_script("arguments[0].value = arguments[1]", input_element, new_value)
|
204 |
+
|
205 |
+
confirm_button = driver.find_element(By.CLASS_NAME, "settingsButtonConfirm")
|
206 |
+
confirm_button.click()
|
207 |
+
except:
|
208 |
+
print("could not set temperature")
|
209 |
+
|
210 |
|
211 |
textarea = driver.find_element(By.CSS_SELECTOR, "textarea")
|
212 |
textarea.send_keys(text)
|
|
|
223 |
data=data={"id":id,"result":"","status":"Error"}
|
224 |
x= requests.post(host,data= data)
|
225 |
return
|
226 |
+
value=""
|
227 |
+
try:
|
228 |
+
messages = driver.find_elements(By.CLASS_NAME, 'messageContain')
|
229 |
+
last_message_contain = messages[len(messages)-2]
|
230 |
+
value = last_message_contain.text
|
231 |
+
value = value[8:len(value)]
|
232 |
+
print(value)
|
233 |
+
if value=="Please, wait...":
|
234 |
+
continue
|
235 |
+
except:
|
236 |
continue
|
237 |
|
238 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
|
240 |
driver.delete_all_cookies()
|
241 |
driver.quit()
|