Update app.py
Browse files
app.py
CHANGED
@@ -46,7 +46,7 @@ service = Service()
|
|
46 |
|
47 |
driver = webdriver.Chrome(options= options,service=service)
|
48 |
|
49 |
-
driver.get("https://yuntian-deng-chatgpt.hf.space/")
|
50 |
|
51 |
|
52 |
class Query(BaseModel):
|
@@ -116,21 +116,15 @@ async def get_answer(q: Query ):
|
|
116 |
def do_ML(id:str,text:str,host:str, trycount:int):
|
117 |
try:
|
118 |
starttime=time.time()
|
119 |
-
driver.get("https://
|
120 |
time.sleep(3+trycount)
|
121 |
-
|
122 |
-
|
123 |
-
time.sleep(1+trycount)
|
124 |
-
alert = driver.switch_to.alert
|
125 |
-
alert.accept()
|
126 |
-
print("alert accepted")
|
127 |
-
time.sleep(1+trycount)
|
128 |
-
id_box = driver.find_element(By.XPATH,'//textarea[@data-testid="textbox"]')
|
129 |
-
id_box.send_keys(text)
|
130 |
time.sleep(1+trycount)
|
131 |
-
|
132 |
-
|
133 |
prev =""
|
|
|
134 |
time.sleep(2)
|
135 |
while True:
|
136 |
time.sleep(2+trycount)
|
@@ -140,11 +134,18 @@ def do_ML(id:str,text:str,host:str, trycount:int):
|
|
140 |
x= requests.post(host,data= data)
|
141 |
return
|
142 |
|
143 |
-
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
if prev!="":
|
146 |
if value==prev:
|
147 |
data={"id":id,"result":value,"status":"Generated"}
|
|
|
148 |
requests.post(host, data=data)
|
149 |
break
|
150 |
prev= value
|
@@ -154,6 +155,7 @@ def do_ML(id:str,text:str,host:str, trycount:int):
|
|
154 |
print(x.text)
|
155 |
|
156 |
except:
|
|
|
157 |
if trycount>3:
|
158 |
data=data={"id":id,"result":"","status":"Error"}
|
159 |
x= requests.post(host,data= data)
|
|
|
46 |
|
47 |
driver = webdriver.Chrome(options= options,service=service)
|
48 |
|
49 |
+
# driver.get("https://yuntian-deng-chatgpt.hf.space/")
|
50 |
|
51 |
|
52 |
class Query(BaseModel):
|
|
|
116 |
def do_ML(id:str,text:str,host:str, trycount:int):
|
117 |
try:
|
118 |
starttime=time.time()
|
119 |
+
driver.get("https://talkai.info/chat/")
|
120 |
time.sleep(3+trycount)
|
121 |
+
textarea = driver.find_element(By.CSS_SELECTOR, "textarea")
|
122 |
+
textarea.send_keys(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
time.sleep(1+trycount)
|
124 |
+
button = driver.find_element(By.CLASS_NAME, "sectionChatFormButton")
|
125 |
+
button.click()
|
126 |
prev =""
|
127 |
+
|
128 |
time.sleep(2)
|
129 |
while True:
|
130 |
time.sleep(2+trycount)
|
|
|
134 |
x= requests.post(host,data= data)
|
135 |
return
|
136 |
|
137 |
+
messages = driver.find_elements(By.CLASS_NAME, 'messageContain')
|
138 |
+
last_message_contain = messages[len(messages)-2]
|
139 |
+
value = last_message_contain.text
|
140 |
+
value = value[8:len(value)]
|
141 |
+
|
142 |
+
if value=="Please, wait...":
|
143 |
+
continue
|
144 |
+
|
145 |
if prev!="":
|
146 |
if value==prev:
|
147 |
data={"id":id,"result":value,"status":"Generated"}
|
148 |
+
driver.delete_all_cookies()
|
149 |
requests.post(host, data=data)
|
150 |
break
|
151 |
prev= value
|
|
|
155 |
print(x.text)
|
156 |
|
157 |
except:
|
158 |
+
driver.delete_all_cookies()
|
159 |
if trycount>3:
|
160 |
data=data={"id":id,"result":"","status":"Error"}
|
161 |
x= requests.post(host,data= data)
|