rishi1985 commited on
Commit
81ac716
1 Parent(s): b6d589f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -70
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import io
3
  from fastapi import FastAPI, File, UploadFile
4
 
@@ -164,16 +163,9 @@ async def get_answer(request: Request ):
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')
171
- # service = Service()
172
- # driver = webdriver.Chrome(options= options,service=service)
173
  try:
174
  starttime=time.time()
175
- # driver.get("https://talkai.info/chat/")
176
- # time.sleep(2+trycount)
177
  driver= None
178
  while True:
179
  try:
@@ -195,34 +187,68 @@ def do_ML(id:str,text:str,host:str, trycount:int,temperature:float):
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)
213
- time.sleep(0.1)
214
- button = driver.find_element(By.CLASS_NAME, "sectionChatFormButton")
215
- button.click()
216
  prev =""
217
 
218
  # time.sleep(2)
219
  while True:
220
  time.sleep(0.2)
221
  currtime= time.time()
222
- if(currtime>starttime+60):
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')
@@ -241,16 +267,13 @@ def do_ML(id:str,text:str,host:str, trycount:int,temperature:float):
241
  driver.quit()
242
  return value
243
 
244
- data=data={"id":id,"result":value,"status":"Generating --keep refreshing"}
245
- x= requests.post(host,data= data)
246
- print(x.text)
247
 
248
  except:
249
  print("Error")
250
  driver.delete_all_cookies()
251
  if trycount>3:
252
- data=data={"id":id,"result":"","status":"Error"}
253
- x= requests.post(host,data= data)
254
  return
255
  driver.quit()
256
  return do_ML(id,text,host,trycount+1)
@@ -291,18 +314,15 @@ async def get_answer(q: Query ):
291
 
292
 
293
  def do_ML2(id:str,text:str,host:str, trycount:int):
294
- # options = ChromeOptions()
295
- # options.add_argument('--no-sandbox')
296
- # options.add_argument('-headless')
297
- # service = Service()
298
- # driver = webdriver.Chrome(options= options,service=service)
299
  try:
300
  starttime=time.time()
301
- # driver.get("https://talkai.info/image/")
302
-
303
-
304
  driver= None
305
  while True:
 
 
 
306
  try:
307
  currtime= time.time()
308
  if(currtime>starttime+10):
@@ -312,35 +332,38 @@ def do_ML2(id:str,text:str,host:str, trycount:int):
312
  # chatq.pop()[0]
313
  t = threading.Thread(target=makeqimg)
314
  t.start()
315
- break;
316
  except Exception as error:
317
  print("Error in popping ", error )
318
  t = threading.Thread(target=makeqimg)
319
  t.start()
320
  time.sleep(0.5)
321
 
322
-
323
-
324
-
325
-
326
-
327
-
328
-
329
-
330
- # time.sleep(2+trycount)
331
- textarea = driver.find_element(By.CSS_SELECTOR, "textarea")
332
- textarea.send_keys(text)
333
- time.sleep(0.1)
334
- button = driver.find_element(By.CLASS_NAME, "sectionChatFormButton")
335
- button.click()
336
  # time.sleep(2)
337
  while True:
338
- time.sleep(0.2+trycount)
339
  currtime= time.time()
340
- if(currtime>starttime+60):
341
- data=data={"id":id,"result":"","status":"Error"}
342
- x= requests.post(host,data= data)
343
- return
 
 
 
 
344
  try:
345
  messages = driver.find_elements(By.XPATH, "//div[@class='messageContain']/p/img")
346
  last_message_contain = messages[len(messages)-2]
@@ -349,13 +372,8 @@ def do_ML2(id:str,text:str,host:str, trycount:int):
349
 
350
  driver.delete_all_cookies()
351
  driver.quit()
352
- return src
353
-
354
 
355
- data={"id":id,"result":src,"status":"Generated"}
356
- requests.post(host, data=data)
357
- driver.delete_all_cookies()
358
- driver.quit()
359
  break
360
  except:
361
  continue
@@ -363,10 +381,9 @@ def do_ML2(id:str,text:str,host:str, trycount:int):
363
  except:
364
  print("Error")
365
  driver.delete_all_cookies()
366
- if trycount>3:
367
- data=data={"id":id,"result":"","status":"Error"}
368
- x= requests.post(host,data= data)
369
- return
370
  driver.quit()
371
  return do_ML2(id,text,host,trycount+1)
372
 
 
 
1
  import io
2
  from fastapi import FastAPI, File, UploadFile
3
 
 
163
 
164
 
165
  def do_ML(id:str,text:str,host:str, trycount:int,temperature:float):
166
+
 
 
 
 
 
167
  try:
168
  starttime=time.time()
 
 
169
  driver= None
170
  while True:
171
  try:
 
187
  if temperature>=0 and temperature<=2:
188
  try:
189
  print("setting temperature ",temperature)
190
+ while True:
191
+ currtime= time.time()
192
+ if(currtime>starttime+10):
193
+ return "Requested Could not be proceed"
194
+
195
+ try:
196
+ setting_button = driver.find_element(By.ID, "openSettings")
197
+ setting_button.click()
198
+ break
199
+ except:
200
+ time.sleep(0.2)
201
+
202
+ while True:
203
+ currtime= time.time()
204
+ if(currtime>starttime+10):
205
+ return "Requested Could not be proceed"
206
+ try:
207
+ input_element = driver.find_element(By.CLASS_NAME,"styled-slider")
208
+ new_value = temperature
209
+ driver.execute_script("arguments[0].value = arguments[1]", input_element, new_value)
210
+ break
211
+ except:
212
+ time.sleep(0.2)
213
+ while True:
214
+ currtime= time.time()
215
+ if(currtime>starttime+10):
216
+ return "Requested Could not be proceed"
217
+ try:
218
+ confirm_button = driver.find_element(By.CLASS_NAME, "settingsButtonConfirm")
219
+ confirm_button.click()
220
+ break
221
+ except:
222
+ time.sleep(0.2)
223
+ except:
224
+ print("could not set temperature")
225
 
 
 
 
226
 
227
+ while True:
228
+ currtime= time.time()
229
+ if(currtime>starttime+10):
230
+ return "Requested Could not be proceed"
231
+ try:
232
+ textarea = driver.find_element(By.CSS_SELECTOR, "textarea")
233
+ textarea.send_keys(text)
234
+
235
+ button = driver.find_element(By.CLASS_NAME, "sectionChatFormButton")
236
+ button.click()
237
+ break
238
  except:
239
+ time.sleep(0.2)
240
 
241
+
 
 
 
 
 
242
  prev =""
243
 
244
  # time.sleep(2)
245
  while True:
246
  time.sleep(0.2)
247
  currtime= time.time()
248
+ if(currtime>starttime+18.5):
249
+
250
+ return "Requested Could not be proceed"
251
+
252
  value=""
253
  try:
254
  messages = driver.find_elements(By.CLASS_NAME, 'messageContain')
 
267
  driver.quit()
268
  return value
269
 
270
+
 
 
271
 
272
  except:
273
  print("Error")
274
  driver.delete_all_cookies()
275
  if trycount>3:
276
+
 
277
  return
278
  driver.quit()
279
  return do_ML(id,text,host,trycount+1)
 
314
 
315
 
316
  def do_ML2(id:str,text:str,host:str, trycount:int):
317
+
 
 
 
 
318
  try:
319
  starttime=time.time()
320
+
 
 
321
  driver= None
322
  while True:
323
+ currtime= time.time()
324
+ if(currtime>starttime+10):
325
+ return "Requested Could not be proceed"
326
  try:
327
  currtime= time.time()
328
  if(currtime>starttime+10):
 
332
  # chatq.pop()[0]
333
  t = threading.Thread(target=makeqimg)
334
  t.start()
335
+ break
336
  except Exception as error:
337
  print("Error in popping ", error )
338
  t = threading.Thread(target=makeqimg)
339
  t.start()
340
  time.sleep(0.5)
341
 
342
+ while True:
343
+ currtime= time.time()
344
+ if(currtime>starttime+10):
345
+ return "Requested Could not be proceed"
346
+ try:
347
+ textarea = driver.find_element(By.CSS_SELECTOR, "textarea")
348
+ textarea.send_keys(text)
349
+ time.sleep(0.1)
350
+ button = driver.find_element(By.CLASS_NAME, "sectionChatFormButton")
351
+ button.click()
352
+ break
353
+ except:
354
+ time.sleep(0.2)
355
+
356
  # time.sleep(2)
357
  while True:
 
358
  currtime= time.time()
359
+ if(currtime>starttime+10):
360
+ return "Requested Could not be proceed"
361
+
362
+ time.sleep(0.2)
363
+ currtime= time.time()
364
+ if(currtime>starttime+18.5):
365
+
366
+ return "Request Could not be proceed"
367
  try:
368
  messages = driver.find_elements(By.XPATH, "//div[@class='messageContain']/p/img")
369
  last_message_contain = messages[len(messages)-2]
 
372
 
373
  driver.delete_all_cookies()
374
  driver.quit()
 
 
375
 
376
+ return src
 
 
 
377
  break
378
  except:
379
  continue
 
381
  except:
382
  print("Error")
383
  driver.delete_all_cookies()
384
+ if trycount>1:
385
+
386
+ return "Request Could not be proceed"
 
387
  driver.quit()
388
  return do_ML2(id,text,host,trycount+1)
389