Update app.py
Browse files
app.py
CHANGED
@@ -99,200 +99,43 @@ chrome_driver_path = '/usr/local/bin/chromedriver-linux64/chromedriver'
|
|
99 |
async def get_answer_llama(request: Request ):
|
100 |
data = await request.json()
|
101 |
text = data['text']
|
102 |
-
text = text.replace('\n', ' : ')
|
103 |
# print("recived ",text)
|
104 |
-
proxy=None
|
105 |
-
|
106 |
-
try:
|
107 |
-
proxy = data['proxy']
|
108 |
-
except:
|
109 |
-
pass
|
110 |
-
print('proxy ip ', proxy )
|
111 |
-
currtime= time.time()
|
112 |
res= ""
|
113 |
-
|
114 |
-
# res = do_ML_LLAMA70b(text,0,proxy)
|
115 |
-
# else:
|
116 |
-
res= do_ML_LLAMA70b_chori(text,0, proxy)
|
117 |
dict={"LLAMA":res}
|
118 |
return JSONResponse(dict)
|
119 |
|
120 |
|
121 |
-
|
122 |
-
async def get_answer_llama2(request: Request ):
|
123 |
-
data = await request.json()
|
124 |
-
text = data['text']
|
125 |
-
text = text.replace('\n', ' : ')
|
126 |
-
# print("recived ",text)
|
127 |
-
proxy=None
|
128 |
-
|
129 |
-
try:
|
130 |
-
proxy = data['proxy']
|
131 |
-
except:
|
132 |
-
pass
|
133 |
-
print('proxy ip ', proxy )
|
134 |
-
currtime= time.time()
|
135 |
-
res= ""
|
136 |
-
|
137 |
-
res = do_ML_LLAMA70b_chori(text,0,proxy)
|
138 |
-
|
139 |
-
|
140 |
-
dict={"LLAMA":res}
|
141 |
-
|
142 |
-
return JSONResponse(dict)
|
143 |
-
|
144 |
-
@app.post("/llama3")
|
145 |
-
async def get_answer_llama3(request: Request ):
|
146 |
-
data = await request.json()
|
147 |
-
text = data['text']
|
148 |
-
text = text.replace('\n', ' : ')
|
149 |
-
# print("recived ",text)
|
150 |
-
proxy=None
|
151 |
-
|
152 |
-
# try:
|
153 |
-
# proxy = data['proxy']
|
154 |
-
# except:
|
155 |
-
# pass
|
156 |
-
# print('proxy ip ', proxy )
|
157 |
-
# currtime= time.time()
|
158 |
-
# res= ""
|
159 |
-
|
160 |
-
res = do_ML_LLAMA70b(text,0,'')
|
161 |
-
|
162 |
-
|
163 |
-
dict={"LLAMA":res}
|
164 |
-
|
165 |
-
return JSONResponse(dict)
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
def do_ML_LLAMA70b_chori(text:str, trycount:int, proxy:str):
|
171 |
-
starttime=time.time()
|
172 |
-
options = ChromeOptions()
|
173 |
-
global llama_last_error
|
174 |
-
options.add_argument('--no-sandbox')
|
175 |
-
options.add_argument('-headless')
|
176 |
-
options.add_argument("start-maximized")
|
177 |
-
# options.add_argument("--ignore-certificate-errors")
|
178 |
-
service = Service(executable_path=chrome_driver_path)
|
179 |
-
driver = webdriver.Chrome(options= options,service=service)
|
180 |
-
driver.get("https://chansung-llama2-with-gradio-chat.hf.space/")
|
181 |
-
try:
|
182 |
-
|
183 |
-
while True:
|
184 |
-
currtime= time.time()
|
185 |
-
if(currtime>starttime+20):
|
186 |
-
driver.delete_all_cookies()
|
187 |
-
llama_last_error= currtime
|
188 |
-
driver.quit()
|
189 |
-
return "Requested Could not be proceed"
|
190 |
-
try:
|
191 |
-
control_panel_span = driver.find_element(By.XPATH,'//span[@class="svelte-s1r2yt" and contains(text(), "Control Panel")]')
|
192 |
-
control_panel_span.click()
|
193 |
-
time.sleep(0.5)
|
194 |
-
input_element = driver.find_elements(By.CSS_SELECTOR,'[data-testid="number-input"]')
|
195 |
-
new_value = "3500" # Replace this with the value you want to set
|
196 |
-
input_element[3].clear() # Clear the current value if needed
|
197 |
-
input_element[3].send_keys(new_value)
|
198 |
-
xpath = "//textarea[@data-testid='textbox' and @placeholder='Ask anything']"
|
199 |
-
textarea = driver.find_element(By.XPATH,xpath)
|
200 |
-
textarea.clear()
|
201 |
-
textarea.send_keys(text)
|
202 |
-
textarea.send_keys("\n")
|
203 |
-
|
204 |
-
break
|
205 |
-
except Exception as e:
|
206 |
-
print(e)
|
207 |
-
continue
|
208 |
-
|
209 |
-
|
210 |
-
prev =""
|
211 |
-
|
212 |
-
time.sleep(2)
|
213 |
-
while True:
|
214 |
-
time.sleep(0.5)
|
215 |
-
currtime= time.time()
|
216 |
-
|
217 |
-
if(currtime>starttime+170):
|
218 |
-
driver.delete_all_cookies()
|
219 |
-
driver.quit()
|
220 |
-
llama_last_error= currtime
|
221 |
-
return "Requested Could not be proceed"
|
222 |
-
|
223 |
-
try:
|
224 |
-
div_element = driver.find_element(By.CSS_SELECTOR,'div.wrap.default.full.svelte-zlszon.generating')
|
225 |
-
print("generating")
|
226 |
-
continue;
|
227 |
-
except:
|
228 |
-
print('done gen ')
|
229 |
-
|
230 |
-
while True:
|
231 |
-
|
232 |
-
try:
|
233 |
-
div_element = driver.find_elements(By.CLASS_NAME,'md.svelte-9tftx4.chatbot')
|
234 |
-
div_element= div_element[len(div_element)-1]
|
235 |
-
# Extract and print the text content of the div element
|
236 |
-
div_text = div_element.text
|
237 |
-
print(div_text)
|
238 |
-
driver.delete_all_cookies()
|
239 |
-
driver.quit()
|
240 |
-
print("Lllama chori")
|
241 |
-
return div_text
|
242 |
-
except Exception as e:
|
243 |
-
return "Error Occureed"
|
244 |
-
|
245 |
-
|
246 |
-
driver.delete_all_cookies()
|
247 |
-
driver.quit()
|
248 |
-
return " --Error Occurred-- "
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
except Exception as e:
|
253 |
-
print(e)
|
254 |
-
driver.delete_all_cookies()
|
255 |
-
driver.quit()
|
256 |
-
currtime= time.time()
|
257 |
-
llama_last_error= currtime
|
258 |
-
return "Error Occurred "
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
def do_ML_LLAMA70b(text:str, trycount:int, proxy:str):
|
263 |
starttime=time.time()
|
264 |
options = ChromeOptions()
|
265 |
global llama_last_error
|
266 |
options.add_argument('--no-sandbox')
|
267 |
options.add_argument('-headless')
|
268 |
options.add_argument("start-maximized")
|
269 |
-
options.add_argument("--ignore-certificate-errors")
|
270 |
-
# proxy_port = "8080"
|
271 |
-
# proxy_ip= proxy
|
272 |
-
# print("pxoxy ip ",proxy_ip)
|
273 |
-
# proxy_ip = f"{proxy_ip}:{proxy_port}"
|
274 |
-
# print("proxy final ", proxy_ip)
|
275 |
-
# options.add_argument(f'--proxy-server=http://{proxy_ip}')
|
276 |
service = Service(executable_path=chrome_driver_path)
|
277 |
driver = webdriver.Chrome(options= options,service=service)
|
278 |
-
driver.get("https://
|
279 |
try:
|
280 |
|
281 |
while True:
|
282 |
currtime= time.time()
|
283 |
-
if(currtime>starttime+
|
284 |
driver.delete_all_cookies()
|
285 |
driver.quit()
|
286 |
-
llama_last_error= currtime
|
287 |
return "Requested Could not be proceed"
|
288 |
try:
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
|
|
|
|
|
|
|
|
296 |
|
297 |
textarea_element.send_keys('\n')
|
298 |
|
@@ -309,25 +152,30 @@ def do_ML_LLAMA70b(text:str, trycount:int, proxy:str):
|
|
309 |
time.sleep(0.5)
|
310 |
currtime= time.time()
|
311 |
|
312 |
-
if(currtime>starttime+
|
313 |
driver.delete_all_cookies()
|
314 |
driver.quit()
|
315 |
|
316 |
-
return
|
317 |
|
|
|
|
|
|
|
|
|
318 |
try:
|
319 |
-
|
320 |
-
|
|
|
|
|
321 |
continue
|
322 |
-
|
323 |
except:
|
324 |
-
print("not
|
325 |
|
326 |
-
element = driver.find_element(By.
|
327 |
-
element_text
|
328 |
-
|
329 |
driver.quit()
|
330 |
-
|
331 |
return element_text
|
332 |
|
333 |
|
@@ -348,181 +196,6 @@ def do_ML_LLAMA70b(text:str, trycount:int, proxy:str):
|
|
348 |
|
349 |
|
350 |
|
351 |
-
def do_ML_LLAMA7b(text:str, trycount:int):
|
352 |
-
starttime=time.time()
|
353 |
-
options = ChromeOptions()
|
354 |
-
options.add_argument('--no-sandbox')
|
355 |
-
options.add_argument('-headless')
|
356 |
-
options.add_argument("start-maximized")
|
357 |
-
service = Service(executable_path=chrome_driver_path)
|
358 |
-
driver = webdriver.Chrome(options= options,service=service)
|
359 |
-
driver.get("https://huggingface-projects-llama-2-7b-chat.hf.space")
|
360 |
-
try:
|
361 |
-
|
362 |
-
while True:
|
363 |
-
currtime= time.time()
|
364 |
-
if(currtime>starttime+20):
|
365 |
-
driver.delete_all_cookies()
|
366 |
-
driver.quit()
|
367 |
-
return "Requested Could not be proceed"
|
368 |
-
try:
|
369 |
-
xpath_expression = '//textarea[@data-testid="textbox"]'
|
370 |
-
textarea_element = driver.find_element(By.XPATH, xpath_expression)
|
371 |
-
|
372 |
-
for line in text.split('\n'):
|
373 |
-
textarea_element.send_keys(line)
|
374 |
-
# Simulate pressing the 'Shift + Enter' keys to add a newline without triggering submit
|
375 |
-
textarea_element.send_keys(Keys.SHIFT + Keys.ENTER)
|
376 |
-
|
377 |
-
span_element = driver.find_element(By.CLASS_NAME, 'svelte-s1r2yt')
|
378 |
-
|
379 |
-
span_element.click()
|
380 |
-
input_element = driver.find_element(By.CSS_SELECTOR, 'input[data-testid="number-input"]')
|
381 |
-
new_value = "2048" # Replace this with the value you want to set
|
382 |
-
input_element.clear()
|
383 |
-
input_element.send_keys(new_value)
|
384 |
-
|
385 |
-
textarea_element.send_keys('\n')
|
386 |
-
|
387 |
-
break
|
388 |
-
except:
|
389 |
-
continue
|
390 |
-
|
391 |
-
|
392 |
-
prev =""
|
393 |
-
|
394 |
-
time.sleep(0.6)
|
395 |
-
while True:
|
396 |
-
time.sleep(0.5)
|
397 |
-
currtime= time.time()
|
398 |
-
|
399 |
-
if(currtime>starttime+170):
|
400 |
-
driver.delete_all_cookies()
|
401 |
-
driver.quit()
|
402 |
-
|
403 |
-
return "Requested Could not be proceed"
|
404 |
-
|
405 |
-
# value=""
|
406 |
-
try:
|
407 |
-
div_element = driver.find_element(By.CLASS_NAME, 'wrap.default.minimal.svelte-zlszon.translucent.hide')
|
408 |
-
element = driver.find_element(By.XPATH,'//div[@data-testid="bot" and contains(@class, "message bot")]')
|
409 |
-
|
410 |
-
x=(element.text)
|
411 |
-
driver.delete_all_cookies()
|
412 |
-
driver.quit()
|
413 |
-
return x
|
414 |
-
except:
|
415 |
-
continue
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
driver.delete_all_cookies()
|
420 |
-
driver.quit()
|
421 |
-
return " --Error Occurred-- "
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
except:
|
426 |
-
driver.delete_all_cookies()
|
427 |
-
driver.quit()
|
428 |
-
return "Error Occurred "
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
def do_ML_LLAMA13b(text:str, trycount:int):
|
435 |
-
starttime=time.time()
|
436 |
-
options = ChromeOptions()
|
437 |
-
options.add_argument('--no-sandbox')
|
438 |
-
options.add_argument('-headless')
|
439 |
-
options.add_argument("start-maximized")
|
440 |
-
service = Service(executable_path=chrome_driver_path)
|
441 |
-
driver = webdriver.Chrome(options= options,service=service)
|
442 |
-
driver.get("https://huggingface-projects-llama-2-13b-chat--mkxgl.hf.space/")
|
443 |
-
try:
|
444 |
-
|
445 |
-
while True:
|
446 |
-
currtime= time.time()
|
447 |
-
if(currtime>starttime+20):
|
448 |
-
driver.delete_all_cookies()
|
449 |
-
driver.quit()
|
450 |
-
return "Requested Could not be proceed"
|
451 |
-
try:
|
452 |
-
xpath_expression = '//textarea[@data-testid="textbox"]'
|
453 |
-
textarea_element = driver.find_element(By.XPATH, xpath_expression)
|
454 |
-
|
455 |
-
for line in text.split('\n'):
|
456 |
-
textarea_element.send_keys(line)
|
457 |
-
# Simulate pressing the 'Shift + Enter' keys to add a newline without triggering submit
|
458 |
-
textarea_element.send_keys(Keys.SHIFT + Keys.ENTER)
|
459 |
-
|
460 |
-
span_element = driver.find_element(By.CLASS_NAME, 'svelte-s1r2yt')
|
461 |
-
|
462 |
-
span_element.click()
|
463 |
-
input_element = driver.find_element(By.CSS_SELECTOR, 'input[data-testid="number-input"]')
|
464 |
-
new_value = "2048" # Replace this with the value you want to set
|
465 |
-
input_element.clear()
|
466 |
-
input_element.send_keys(new_value)
|
467 |
-
|
468 |
-
textarea_element.send_keys('\n')
|
469 |
-
|
470 |
-
break
|
471 |
-
except:
|
472 |
-
continue
|
473 |
-
|
474 |
-
|
475 |
-
prev =""
|
476 |
-
|
477 |
-
time.sleep(0.6)
|
478 |
-
while True:
|
479 |
-
time.sleep(0.5)
|
480 |
-
currtime= time.time()
|
481 |
-
|
482 |
-
if(currtime>starttime+170):
|
483 |
-
driver.delete_all_cookies()
|
484 |
-
driver.quit()
|
485 |
-
|
486 |
-
return "Requested Could not be proceed"
|
487 |
-
|
488 |
-
try:
|
489 |
-
queue_element = driver.find_element(By.CLASS_NAME,'progress-text')
|
490 |
-
queue_text = queue_element.text
|
491 |
-
print(queue_text)
|
492 |
-
if "queue" in queue_text:
|
493 |
-
print("Queue is present")
|
494 |
-
driver.delete_all_cookies()
|
495 |
-
driver.quit()
|
496 |
-
return do_ML_LLAMA7b(text, trycount)
|
497 |
-
except:
|
498 |
-
pass
|
499 |
-
|
500 |
-
# value=""
|
501 |
-
try:
|
502 |
-
div_element = driver.find_element(By.CLASS_NAME, 'wrap.default.minimal.svelte-zlszon.translucent.hide')
|
503 |
-
element = driver.find_element(By.XPATH,'//div[@data-testid="bot" and contains(@class, "message bot")]')
|
504 |
-
|
505 |
-
x=(element.text)
|
506 |
-
driver.delete_all_cookies()
|
507 |
-
driver.quit()
|
508 |
-
return x
|
509 |
-
except:
|
510 |
-
continue
|
511 |
-
|
512 |
-
|
513 |
-
driver.delete_all_cookies()
|
514 |
-
driver.quit()
|
515 |
-
|
516 |
-
return " --Error Occurred-- "
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
except:
|
521 |
-
driver.delete_all_cookies()
|
522 |
-
driver.quit()
|
523 |
-
return "Error Occurred "
|
524 |
-
|
525 |
-
|
526 |
|
527 |
|
528 |
########## MPT
|
@@ -938,7 +611,7 @@ async def do_falcon180(text):
|
|
938 |
textarea_element.send_keys('\n')
|
939 |
break
|
940 |
except Exception as e:
|
941 |
-
print(e
|
942 |
continue
|
943 |
old_text=""
|
944 |
while True:
|
|
|
99 |
async def get_answer_llama(request: Request ):
|
100 |
data = await request.json()
|
101 |
text = data['text']
|
|
|
102 |
# print("recived ",text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
res= ""
|
104 |
+
res= do_ML_LLAMA70b(text,0)
|
|
|
|
|
|
|
105 |
dict={"LLAMA":res}
|
106 |
return JSONResponse(dict)
|
107 |
|
108 |
|
109 |
+
def do_ML_LLAMA70b(text:str, trycount:int):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
starttime=time.time()
|
111 |
options = ChromeOptions()
|
112 |
global llama_last_error
|
113 |
options.add_argument('--no-sandbox')
|
114 |
options.add_argument('-headless')
|
115 |
options.add_argument("start-maximized")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
service = Service(executable_path=chrome_driver_path)
|
117 |
driver = webdriver.Chrome(options= options,service=service)
|
118 |
+
driver.get("https://ysharma-explore-llamav2-with-tgi.hf.space/")
|
119 |
try:
|
120 |
|
121 |
while True:
|
122 |
currtime= time.time()
|
123 |
+
if(currtime>starttime+30):
|
124 |
driver.delete_all_cookies()
|
125 |
driver.quit()
|
|
|
126 |
return "Requested Could not be proceed"
|
127 |
try:
|
128 |
+
span_element = driver.find_element(By.CLASS_NAME, 'svelte-s1r2yt')
|
129 |
+
span_element.click()
|
130 |
+
input_element = driver.find_elements(By.CSS_SELECTOR, 'input[data-testid="number-input"]')
|
131 |
+
new_value = "2000"
|
132 |
+
input_element[1].clear()
|
133 |
+
input_element[1].send_keys(new_value)
|
134 |
+
xpath_expression = '//textarea[@data-testid="textbox"]'
|
135 |
+
textarea_element = driver.find_element(By.XPATH, xpath_expression)
|
136 |
+
for line in text.split('\n'):
|
137 |
+
textarea_element.send_keys(text)
|
138 |
+
textarea_element.send_keys(Keys.SHIFT + Keys.ENTER)
|
139 |
|
140 |
textarea_element.send_keys('\n')
|
141 |
|
|
|
152 |
time.sleep(0.5)
|
153 |
currtime= time.time()
|
154 |
|
155 |
+
if(currtime>starttime+178):
|
156 |
driver.delete_all_cookies()
|
157 |
driver.quit()
|
158 |
|
159 |
+
return prev
|
160 |
|
161 |
+
element_selector = '.wrap.default.minimal.svelte-119qaqt.translucent.generating'
|
162 |
+
|
163 |
+
|
164 |
+
# print(x)
|
165 |
try:
|
166 |
+
element = driver.find_element(By.CSS_SELECTOR,element_selector)
|
167 |
+
print("generating")
|
168 |
+
element = driver.find_element(By.XPATH,'//div[@data-testid="bot" and contains(@class, "message bot")]')
|
169 |
+
prev=(element.text)
|
170 |
continue
|
|
|
171 |
except:
|
172 |
+
print("Element is not present.")
|
173 |
|
174 |
+
element = driver.find_element(By.XPATH,'//div[@data-testid="bot" and contains(@class, "message bot")]')
|
175 |
+
element_text= element.text
|
176 |
+
|
177 |
driver.quit()
|
178 |
+
|
179 |
return element_text
|
180 |
|
181 |
|
|
|
196 |
|
197 |
|
198 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
|
201 |
########## MPT
|
|
|
611 |
textarea_element.send_keys('\n')
|
612 |
break
|
613 |
except Exception as e:
|
614 |
+
print(e)
|
615 |
continue
|
616 |
old_text=""
|
617 |
while True:
|