rishi1985 commited on
Commit
4708156
1 Parent(s): 440bfa0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -0
app.py CHANGED
@@ -482,4 +482,91 @@ def do_ML_FALCON(text:str, trycount:int):
482
 
483
 
484
 
 
485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
 
483
 
484
 
485
+ '''Star Code'''
486
 
487
+
488
+ @app.post("/starcode")
489
+ async def get_answer_falcon(request: Request ):
490
+ data = await request.json()
491
+ text = data['text']
492
+ print("recived ",text)
493
+ res= do_ML_STARCODE(text,0)
494
+
495
+ dict={"RESULT":res}
496
+
497
+ return JSONResponse(dict)
498
+
499
+
500
+
501
+
502
+
503
+
504
+ def do_ML_STARCODE(text:str, trycount:int):
505
+ starttime=time.time()
506
+ options = ChromeOptions()
507
+ options.add_argument('--no-sandbox')
508
+ options.add_argument('-headless')
509
+ options.add_argument("start-maximized")
510
+ service = Service(executable_path=chrome_driver_path)
511
+ driver = webdriver.Chrome(options= options,service=service)
512
+ driver.get("https://huggingfaceh4-starchat-playground.hf.space/")
513
+ try:
514
+
515
+ while True:
516
+ currtime= time.time()
517
+ if(currtime>starttime+20):
518
+ return "Requested Could not be proceed"
519
+ try:
520
+ textarea_element = driver.find_element(By.CSS_SELECTOR,'textarea[placeholder="Enter your message here"]')
521
+
522
+ for line in text.split('\n'):
523
+ textarea_element.send_keys(line)
524
+ # Simulate pressing the 'Shift + Enter' keys to add a newline without triggering submit
525
+ textarea_element.send_keys(Keys.SHIFT + Keys.ENTER)
526
+ textarea_element.send_keys('\n')
527
+ break
528
+ except:
529
+ continue
530
+
531
+
532
+ prev =""
533
+
534
+ # time.sleep(2)
535
+ while True:
536
+ time.sleep(0.5)
537
+ currtime= time.time()
538
+
539
+ if(currtime>starttime+170):
540
+ driver.delete_all_cookies()
541
+ driver.quit()
542
+
543
+ return "Requested Could not be proceed"
544
+
545
+ try:
546
+ div_element = driver.find_element(By.CLASS_NAME,'svelte-j1gjts.generating')
547
+ continue
548
+ except:
549
+ pass
550
+ # value=""
551
+ try:
552
+ div_element = driver.find_element(By.CSS_SELECTOR,'div[data-testid="bot"]')
553
+ text_content = div_element.text
554
+ print(text_content)
555
+ return text_content
556
+
557
+ except Exception as e:
558
+ print(e)
559
+ continue
560
+
561
+
562
+
563
+ driver.quit()
564
+ return " --Error Occurred-- "
565
+
566
+
567
+
568
+ except:
569
+ print("Error")
570
+
571
+ return "Error Occureed"
572
+