Update app.py
Browse files
app.py
CHANGED
|
@@ -316,95 +316,6 @@ def do_ML_MPT(text:str, trycount:int):
|
|
| 316 |
'''Falcon 40 b intruct'''
|
| 317 |
|
| 318 |
|
| 319 |
-
@app.post("/falcon")
|
| 320 |
-
async def get_answer_falcon(request: Request ):
|
| 321 |
-
data = await request.json()
|
| 322 |
-
text = data['text']
|
| 323 |
-
print("recived ",text)
|
| 324 |
-
res= do_ML_FALCON(text,0)
|
| 325 |
-
|
| 326 |
-
dict={"FALCON":res}
|
| 327 |
-
|
| 328 |
-
return JSONResponse(dict)
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
def do_ML_FALCON(text:str, trycount:int):
|
| 336 |
-
starttime=time.time()
|
| 337 |
-
options = ChromeOptions()
|
| 338 |
-
options.add_argument('--no-sandbox')
|
| 339 |
-
options.add_argument('-headless')
|
| 340 |
-
options.add_argument("start-maximized")
|
| 341 |
-
service = Service(executable_path=chrome_driver_path)
|
| 342 |
-
driver = webdriver.Chrome(options= options,service=service)
|
| 343 |
-
driver.get("https://huggingfaceh4-falcon-chat.hf.space")
|
| 344 |
-
try:
|
| 345 |
-
|
| 346 |
-
while True:
|
| 347 |
-
currtime= time.time()
|
| 348 |
-
if(currtime>starttime+20):
|
| 349 |
-
driver.delete_all_cookies()
|
| 350 |
-
driver.quit()
|
| 351 |
-
return "Requested Could not be proceed"
|
| 352 |
-
try:
|
| 353 |
-
textarea_element = driver.find_element(By.CSS_SELECTOR,'textarea[placeholder="Hello Falcon !!"]')
|
| 354 |
-
|
| 355 |
-
for line in text.split('\n'):
|
| 356 |
-
textarea_element.send_keys(line)
|
| 357 |
-
# Simulate pressing the 'Shift + Enter' keys to add a newline without triggering submit
|
| 358 |
-
textarea_element.send_keys(Keys.SHIFT + Keys.ENTER)
|
| 359 |
-
textarea_element.send_keys('\n')
|
| 360 |
-
break
|
| 361 |
-
except:
|
| 362 |
-
continue
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
prev =""
|
| 366 |
-
|
| 367 |
-
# time.sleep(2)
|
| 368 |
-
while True:
|
| 369 |
-
time.sleep(0.5)
|
| 370 |
-
currtime= time.time()
|
| 371 |
-
|
| 372 |
-
if(currtime>starttime+170):
|
| 373 |
-
driver.delete_all_cookies()
|
| 374 |
-
driver.quit()
|
| 375 |
-
|
| 376 |
-
return "Requested Could not be proceed"
|
| 377 |
-
|
| 378 |
-
# value=""
|
| 379 |
-
try:
|
| 380 |
-
div_element = driver.find_element(By.CSS_SELECTOR,'div[data-testid="bot"]')
|
| 381 |
-
div_text = div_element.text
|
| 382 |
-
print(div_text)
|
| 383 |
-
if prev==div_text and prev !="":
|
| 384 |
-
driver.quit()
|
| 385 |
-
return div_text
|
| 386 |
-
|
| 387 |
-
prev= div_text
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
except Exception as e:
|
| 391 |
-
print(e)
|
| 392 |
-
continue
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
driver.quit()
|
| 397 |
-
return " --Error Occurred-- "
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
except:
|
| 402 |
-
print("Error")
|
| 403 |
-
driver.delete_all_cookies()
|
| 404 |
-
driver.quit()
|
| 405 |
-
|
| 406 |
-
return "Error Occureed"
|
| 407 |
-
|
| 408 |
|
| 409 |
|
| 410 |
'''Star Code'''
|
|
@@ -503,68 +414,6 @@ def do_ML_STARCODE(text:str, trycount:int):
|
|
| 503 |
return "Error Occureed"
|
| 504 |
|
| 505 |
|
| 506 |
-
@app.post("/chatgpt")
|
| 507 |
-
async def get_answer_llama3(request: Request ):
|
| 508 |
-
data = await request.json()
|
| 509 |
-
msges= data['messages']
|
| 510 |
-
print("recievoed , ", msges )
|
| 511 |
-
return do_chat_gpt(msges)
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
def do_chat_gpt(msges):
|
| 518 |
-
starttime=time.time()
|
| 519 |
-
options = ChromeOptions()
|
| 520 |
-
options.add_argument('--no-sandbox')
|
| 521 |
-
options.add_argument('-headless')
|
| 522 |
-
options.add_argument("start-maximized")
|
| 523 |
-
service = Service(executable_path=chrome_driver_path)
|
| 524 |
-
driver = webdriver.Chrome(options= options,service=service)
|
| 525 |
-
driver.get("https://openskyml-pigeon-chat.hf.space/")
|
| 526 |
-
base=""
|
| 527 |
-
for message in msges:
|
| 528 |
-
base += "%s: %s \n" % (message["role"], message["content"])
|
| 529 |
-
base += "assistant:"
|
| 530 |
-
print("base ",base)
|
| 531 |
-
try:
|
| 532 |
-
while True:
|
| 533 |
-
curr= time.time()
|
| 534 |
-
if curr- starttime>20:
|
| 535 |
-
driver.quit()
|
| 536 |
-
return "Error -1"
|
| 537 |
-
try:
|
| 538 |
-
textarea_element = driver.find_element(By.XPATH,'//textarea[@placeholder="Type a message..."]')
|
| 539 |
-
for line in base.split('\n'):
|
| 540 |
-
textarea_element.send_keys(line)
|
| 541 |
-
textarea_element.send_keys(Keys.SHIFT + Keys.ENTER)
|
| 542 |
-
time.sleep(0.5)
|
| 543 |
-
textarea_element.send_keys('\n')
|
| 544 |
-
break
|
| 545 |
-
except Exception as e:
|
| 546 |
-
print(e)
|
| 547 |
-
time.sleep(0.5)
|
| 548 |
-
continue
|
| 549 |
-
while True:
|
| 550 |
-
curr= time.time()
|
| 551 |
-
if curr- starttime>175:
|
| 552 |
-
driver.quit()
|
| 553 |
-
return "Error -1"
|
| 554 |
-
try:
|
| 555 |
-
div_element = driver.find_element(By.CSS_SELECTOR,'div[data-testid="bot"]')
|
| 556 |
-
text = div_element.text
|
| 557 |
-
print(text)
|
| 558 |
-
if text=="":
|
| 559 |
-
raise ValueError("Empty text")
|
| 560 |
-
driver.quit()
|
| 561 |
-
return text
|
| 562 |
-
except Exception as e:
|
| 563 |
-
print(e)
|
| 564 |
-
time.sleep(0.5)
|
| 565 |
-
except:
|
| 566 |
-
driver.quit()
|
| 567 |
-
return "Error"
|
| 568 |
|
| 569 |
|
| 570 |
@app.post("/falcon180b")
|
|
@@ -587,9 +436,9 @@ async def do_falcon180(text):
|
|
| 587 |
options.add_argument("start-maximized")
|
| 588 |
service = Service(executable_path=chrome_driver_path)
|
| 589 |
driver = webdriver.Chrome(options= options,service=service)
|
| 590 |
-
driver.get("https://tiiuae-falcon-180b-demo.hf.space
|
| 591 |
# driver.get("https://ysharma-falcon-180b-demo.hf.space/")
|
| 592 |
-
|
| 593 |
try:
|
| 594 |
while True:
|
| 595 |
try:
|
|
|
|
| 316 |
'''Falcon 40 b intruct'''
|
| 317 |
|
| 318 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
|
| 320 |
|
| 321 |
'''Star Code'''
|
|
|
|
| 414 |
return "Error Occureed"
|
| 415 |
|
| 416 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
|
| 418 |
|
| 419 |
@app.post("/falcon180b")
|
|
|
|
| 436 |
options.add_argument("start-maximized")
|
| 437 |
service = Service(executable_path=chrome_driver_path)
|
| 438 |
driver = webdriver.Chrome(options= options,service=service)
|
| 439 |
+
# driver.get("https://tiiuae-falcon-180b-demo.hf.space")
|
| 440 |
# driver.get("https://ysharma-falcon-180b-demo.hf.space/")
|
| 441 |
+
driver.get("https://lunarflu-falcon-180b-demo-duplicate.hf.space")
|
| 442 |
try:
|
| 443 |
while True:
|
| 444 |
try:
|