Update app.py
Browse files
app.py
CHANGED
@@ -97,7 +97,19 @@ async def get_answer_llama(request: Request ):
|
|
97 |
data = await request.json()
|
98 |
text = data['text']
|
99 |
print("recived ",text)
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
dict={"LLAMA":res}
|
103 |
|
@@ -106,7 +118,7 @@ async def get_answer_llama(request: Request ):
|
|
106 |
|
107 |
|
108 |
|
109 |
-
def
|
110 |
starttime=time.time()
|
111 |
options = ChromeOptions()
|
112 |
options.add_argument('--no-sandbox')
|
@@ -177,7 +189,93 @@ def do_ML_LLAMA(text:str, trycount:int):
|
|
177 |
|
178 |
except:
|
179 |
return "Error Occurred "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
|
183 |
|
@@ -294,6 +392,94 @@ def do_ML_MPT(text:str, trycount:int):
|
|
294 |
return do_ML_MPT(text,trycount+1)
|
295 |
|
296 |
|
297 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
298 |
|
299 |
|
|
|
97 |
data = await request.json()
|
98 |
text = data['text']
|
99 |
print("recived ",text)
|
100 |
+
|
101 |
+
try:
|
102 |
+
model = data['model']
|
103 |
+
if model == '13b':
|
104 |
+
print('using 13b')
|
105 |
+
res= do_ML_LLAMA13b(text,0)
|
106 |
+
dict={"LLAMA":res}
|
107 |
+
return JSONResponse(dict)
|
108 |
+
except:
|
109 |
+
print("Using 7b")
|
110 |
+
|
111 |
+
|
112 |
+
res= do_ML_LLAMA13b(text,0)
|
113 |
|
114 |
dict={"LLAMA":res}
|
115 |
|
|
|
118 |
|
119 |
|
120 |
|
121 |
+
def do_ML_LLAMA7b(text:str, trycount:int):
|
122 |
starttime=time.time()
|
123 |
options = ChromeOptions()
|
124 |
options.add_argument('--no-sandbox')
|
|
|
189 |
|
190 |
except:
|
191 |
return "Error Occurred "
|
192 |
+
|
193 |
+
|
194 |
+
|
195 |
+
|
196 |
+
|
197 |
+
def do_ML_LLAMA13b(text:str, trycount:int):
|
198 |
+
starttime=time.time()
|
199 |
+
options = ChromeOptions()
|
200 |
+
options.add_argument('--no-sandbox')
|
201 |
+
options.add_argument('-headless')
|
202 |
+
options.add_argument("start-maximized")
|
203 |
+
service = Service(executable_path=chrome_driver_path)
|
204 |
+
driver = webdriver.Chrome(options= options,service=service)
|
205 |
+
driver.get("https://huggingface-projects-llama-2-13b-chat--mkxgl.hf.space/")
|
206 |
+
try:
|
207 |
+
|
208 |
+
while True:
|
209 |
+
currtime= time.time()
|
210 |
+
if(currtime>starttime+20):
|
211 |
+
return "Requested Could not be proceed"
|
212 |
+
try:
|
213 |
+
xpath_expression = '//textarea[@data-testid="textbox"]'
|
214 |
+
textarea_element = driver.find_element(By.XPATH, xpath_expression)
|
215 |
+
|
216 |
+
for line in text.split('\n'):
|
217 |
+
textarea_element.send_keys(line)
|
218 |
+
# Simulate pressing the 'Shift + Enter' keys to add a newline without triggering submit
|
219 |
+
textarea_element.send_keys(Keys.SHIFT + Keys.ENTER)
|
220 |
+
|
221 |
+
span_element = driver.find_element(By.CLASS_NAME, 'svelte-s1r2yt')
|
222 |
+
|
223 |
+
span_element.click()
|
224 |
+
input_element = driver.find_element(By.CSS_SELECTOR, 'input[data-testid="number-input"]')
|
225 |
+
new_value = "2048" # Replace this with the value you want to set
|
226 |
+
input_element.clear()
|
227 |
+
input_element.send_keys(new_value)
|
228 |
+
|
229 |
+
textarea_element.send_keys('\n')
|
230 |
+
|
231 |
+
break
|
232 |
+
except:
|
233 |
+
continue
|
234 |
+
|
235 |
+
|
236 |
+
prev =""
|
237 |
|
238 |
+
time.sleep(0.6)
|
239 |
+
while True:
|
240 |
+
time.sleep(0.5)
|
241 |
+
currtime= time.time()
|
242 |
+
|
243 |
+
if(currtime>starttime+170):
|
244 |
+
driver.delete_all_cookies()
|
245 |
+
driver.quit()
|
246 |
+
|
247 |
+
return "Requested Could not be proceed"
|
248 |
+
|
249 |
+
try:
|
250 |
+
queue_element = driver.find_element(By.CLASS_NAME,'progress-text')
|
251 |
+
queue_text = queue_element.text
|
252 |
+
print(queue_text)
|
253 |
+
if "queue" in queue_text:
|
254 |
+
print("Queue is present")
|
255 |
+
return do_ML_LLAMA7b(text, trycount)
|
256 |
+
except:
|
257 |
+
pass
|
258 |
+
|
259 |
+
# value=""
|
260 |
+
try:
|
261 |
+
div_element = driver.find_element(By.CLASS_NAME, 'wrap.default.minimal.svelte-zlszon.translucent.hide')
|
262 |
+
element = driver.find_element(By.XPATH,'//div[@data-testid="bot" and contains(@class, "message bot")]')
|
263 |
+
|
264 |
+
x=(element.text)
|
265 |
+
return x
|
266 |
+
except:
|
267 |
+
continue
|
268 |
+
|
269 |
+
|
270 |
+
|
271 |
+
|
272 |
+
return " --Error Occurred-- "
|
273 |
+
|
274 |
+
|
275 |
+
|
276 |
+
except:
|
277 |
+
return "Error Occurred "
|
278 |
+
|
279 |
|
280 |
|
281 |
|
|
|
392 |
return do_ML_MPT(text,trycount+1)
|
393 |
|
394 |
|
395 |
+
'''Falcon 40 b intruct'''
|
396 |
+
|
397 |
+
|
398 |
+
@app.post("/falcon")
|
399 |
+
async def get_answer_falcon(request: Request ):
|
400 |
+
data = await request.json()
|
401 |
+
text = data['text']
|
402 |
+
print("recived ",text)
|
403 |
+
res= do_ML_FALCON(text,0)
|
404 |
+
|
405 |
+
dict={"FALCON":res}
|
406 |
+
|
407 |
+
return JSONResponse(dict)
|
408 |
+
|
409 |
+
|
410 |
+
|
411 |
+
|
412 |
+
|
413 |
+
|
414 |
+
def do_ML_FALCON(text:str, trycount:int):
|
415 |
+
starttime=time.time()
|
416 |
+
options = ChromeOptions()
|
417 |
+
options.add_argument('--no-sandbox')
|
418 |
+
options.add_argument('-headless')
|
419 |
+
options.add_argument("start-maximized")
|
420 |
+
service = Service(executable_path=chrome_driver_path)
|
421 |
+
driver = webdriver.Chrome(options= options,service=service)
|
422 |
+
driver.get("https://huggingfaceh4-falcon-chat.hf.space")
|
423 |
+
try:
|
424 |
+
|
425 |
+
while True:
|
426 |
+
currtime= time.time()
|
427 |
+
if(currtime>starttime+20):
|
428 |
+
return "Requested Could not be proceed"
|
429 |
+
try:
|
430 |
+
textarea_element = driver.find_element(By.CSS_SELECTOR,'textarea[placeholder="Hello Falcon !!"]')
|
431 |
+
|
432 |
+
for line in text.split('\n'):
|
433 |
+
textarea_element.send_keys(line)
|
434 |
+
# Simulate pressing the 'Shift + Enter' keys to add a newline without triggering submit
|
435 |
+
textarea_element.send_keys(Keys.SHIFT + Keys.ENTER)
|
436 |
+
textarea_element.send_keys('\n')
|
437 |
+
break
|
438 |
+
except:
|
439 |
+
continue
|
440 |
+
|
441 |
+
|
442 |
+
prev =""
|
443 |
+
|
444 |
+
# time.sleep(2)
|
445 |
+
while True:
|
446 |
+
time.sleep(0.5)
|
447 |
+
currtime= time.time()
|
448 |
+
|
449 |
+
if(currtime>starttime+170):
|
450 |
+
driver.delete_all_cookies()
|
451 |
+
driver.quit()
|
452 |
+
|
453 |
+
return "Requested Could not be proceed"
|
454 |
+
|
455 |
+
# value=""
|
456 |
+
try:
|
457 |
+
div_element = driver.find_element(By.CSS_SELECTOR,'div[data-testid="bot"]')
|
458 |
+
div_text = div_element.text
|
459 |
+
print(div_text)
|
460 |
+
if prev==div_text and prev !="":
|
461 |
+
driver.quit()
|
462 |
+
return div_text
|
463 |
+
|
464 |
+
prev= div_text
|
465 |
+
|
466 |
+
|
467 |
+
except Exception as e:
|
468 |
+
print(e)
|
469 |
+
continue
|
470 |
+
|
471 |
+
|
472 |
+
|
473 |
+
driver.quit()
|
474 |
+
return " --Error Occurred-- "
|
475 |
+
|
476 |
+
|
477 |
+
|
478 |
+
except:
|
479 |
+
print("Error")
|
480 |
+
|
481 |
+
return "Error Occureed"
|
482 |
+
|
483 |
+
|
484 |
|
485 |
|