Update app.py
Browse files
app.py
CHANGED
@@ -640,8 +640,179 @@ async def do_falcon180(text):
|
|
640 |
continue
|
641 |
except:
|
642 |
driver.quit()
|
|
|
|
|
643 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
644 |
|
|
|
|
|
|
|
|
|
645 |
|
646 |
|
647 |
|
|
|
640 |
continue
|
641 |
except:
|
642 |
driver.quit()
|
643 |
+
|
644 |
+
|
645 |
|
646 |
+
|
647 |
+
@app.post("/wizlm70b")
|
648 |
+
async def get_answer_falcon180(request: Request):
|
649 |
+
data = await request.json()
|
650 |
+
text= data['text']
|
651 |
+
print("recievoed , ", text )
|
652 |
+
return do_wizard70b(text)
|
653 |
+
|
654 |
+
|
655 |
+
def do_wizard70b(text):
|
656 |
+
starttime=time.time()
|
657 |
+
options = ChromeOptions()
|
658 |
+
options.add_argument('--no-sandbox')
|
659 |
+
options.add_argument('-headless')
|
660 |
+
options.add_argument("start-maximized")
|
661 |
+
service = Service(executable_path=chrome_driver_path)
|
662 |
+
driver = webdriver.Chrome(options= options,service=service)
|
663 |
+
driver.get("https://chat.lmsys.org/")
|
664 |
+
while True:
|
665 |
+
curr= time.time()
|
666 |
+
if curr- starttime>10:
|
667 |
+
driver.delete_all_cookies()
|
668 |
+
driver.quit()
|
669 |
+
return "Error-- 1"
|
670 |
+
try:
|
671 |
+
button = driver.find_element(By.XPATH, "//button[contains(@class, 'svelte-kqij2n') and text()='Single Model']")
|
672 |
+
button.click()
|
673 |
+
break
|
674 |
+
except Exception as e:
|
675 |
+
print(e)
|
676 |
+
time.sleep(0.5)
|
677 |
+
# return driver.page_source
|
678 |
+
|
679 |
+
# while True:
|
680 |
+
# curr= time.time()
|
681 |
+
# if curr- starttime>50:
|
682 |
+
# driver.delete_all_cookies()
|
683 |
+
# driver.quit()
|
684 |
+
# return "Error-- 2"
|
685 |
+
# try:
|
686 |
+
# input_element = driver.find_elements(By.CLASS_NAME,'border-none')
|
687 |
+
# # Send text to the <input> element
|
688 |
+
# input_element[2].clear()
|
689 |
+
# input_element[2].send_keys('wizardlm-70b\n')
|
690 |
+
# span_element = driver.find_elements(By.XPATH,'//span[text()="Parameters"]')
|
691 |
+
# span_element[2].click()
|
692 |
+
# input_element = driver.find_elements(By.XPATH ,'//input[@data-testid="number-input"]')
|
693 |
+
# input_element[8].clear() # Clear any existing value
|
694 |
+
# input_element[8].send_keys('1024')
|
695 |
+
# break
|
696 |
+
# except Exception as e:
|
697 |
+
# print(e)
|
698 |
+
# time.sleep(0.5)
|
699 |
+
time.sleep(1)
|
700 |
+
while True:
|
701 |
+
curr= time.time()
|
702 |
+
if curr- starttime>60:
|
703 |
+
driver.delete_all_cookies()
|
704 |
+
driver.quit()
|
705 |
+
return "Error-- 3"
|
706 |
+
try:
|
707 |
+
textarea = driver.find_elements(By.XPATH,'//textarea[@data-testid="textbox"]') # You can also use other locators like by_id, by_name, by_class_name, etc.
|
708 |
+
textarea[2].clear()
|
709 |
+
for line in text.split('\n'):
|
710 |
+
textarea[2].send_keys(line)
|
711 |
+
textarea[2].send_keys('\n')
|
712 |
+
except Exception as e:
|
713 |
+
print(e)
|
714 |
+
time.sleep(0.5)
|
715 |
+
|
716 |
+
time.sleep(2)
|
717 |
+
while True:
|
718 |
+
curr= time.time()
|
719 |
+
if curr- starttime>178:
|
720 |
+
driver.delete_all_cookies()
|
721 |
+
driver.quit()
|
722 |
+
return "Error-- 3 -- timeout"
|
723 |
+
try:
|
724 |
+
element = driver.find_element(By.CSS_SELECTOR, '.generating')
|
725 |
+
print("geberating")
|
726 |
+
time.sleep(0.5)
|
727 |
+
except:
|
728 |
+
print("Element with 'generating' keyword in class is not present.")
|
729 |
+
div_element = driver.find_element(By.XPATH,'//div[@data-testid="bot"]')
|
730 |
+
extracted_text = div_element.text
|
731 |
+
driver.delete_all_cookies()
|
732 |
+
driver.quit()
|
733 |
+
return extracted_text
|
734 |
+
|
735 |
+
|
736 |
+
|
737 |
+
|
738 |
+
|
739 |
+
#####PALM 2
|
740 |
+
|
741 |
+
@app.post("/palm2")
|
742 |
+
async def get_answer_llama(request: Request ):
|
743 |
+
data = await request.json()
|
744 |
+
text = data['text']
|
745 |
+
# print("recived ",text)
|
746 |
+
res= ""
|
747 |
+
res= do_ML_PALM(text,0)
|
748 |
+
dict={"BOT":res}
|
749 |
+
return JSONResponse(dict)
|
750 |
+
|
751 |
+
|
752 |
+
def do_ML_PALM(text:str, trycount:int):
|
753 |
+
starttime=time.time()
|
754 |
+
options = ChromeOptions()
|
755 |
+
options.add_argument('--no-sandbox')
|
756 |
+
options.add_argument('-headless')
|
757 |
+
options.add_argument("start-maximized")
|
758 |
+
service = Service(executable_path=chrome_driver_path)
|
759 |
+
driver = webdriver.Chrome(options= options,service=service)
|
760 |
+
driver.get('https://chansung-palm-with-gradio-chat.hf.space')
|
761 |
+
try:
|
762 |
+
while True:
|
763 |
+
curr = time.time()
|
764 |
+
if curr-starttime>178:
|
765 |
+
driver.delete_all_cookies()
|
766 |
+
driver.quit()
|
767 |
+
return 'Error -1'
|
768 |
+
|
769 |
+
try:
|
770 |
+
xpath = "//textarea[@data-testid='textbox' and @placeholder='Ask anything']"
|
771 |
+
textarea = driver.find_element(By.XPATH,xpath)
|
772 |
+
textarea.clear()
|
773 |
+
for line in text.split('\n'):
|
774 |
+
textarea.send_keys(line)
|
775 |
+
textarea.send_keys("\n")
|
776 |
+
break
|
777 |
+
except:
|
778 |
+
continue
|
779 |
+
time.sleep(1.5)
|
780 |
+
while True:
|
781 |
+
if curr-starttime>178:
|
782 |
+
driver.delete_all_cookies()
|
783 |
+
driver.quit()
|
784 |
+
return 'Error -2'
|
785 |
+
try:
|
786 |
+
div_element = driver.find_element(By.CSS_SELECTOR,'div.wrap.default.full.svelte-zlszon.generating')
|
787 |
+
continue
|
788 |
+
except:
|
789 |
+
print('fail')
|
790 |
+
try:
|
791 |
+
div_element = driver.find_elements(By.CLASS_NAME,'md.svelte-9tftx4.chatbot')
|
792 |
+
div_element= div_element[1]
|
793 |
+
# Extract and print the text content of the div element
|
794 |
+
div_text = div_element.text
|
795 |
+
if div_text=="":
|
796 |
+
continue
|
797 |
+
driver.delete_all_cookies()
|
798 |
+
driver.quit()
|
799 |
+
return div_text
|
800 |
+
except:
|
801 |
+
time.sleep(0.5)
|
802 |
+
continue
|
803 |
+
|
804 |
+
|
805 |
+
except Exception as e:
|
806 |
+
print(e)
|
807 |
+
driver.delete_all_cookies()
|
808 |
+
driver.quit()
|
809 |
+
return "Error 3"
|
810 |
+
|
811 |
|
812 |
+
|
813 |
+
|
814 |
+
|
815 |
+
|
816 |
|
817 |
|
818 |
|