Update app.py
Browse files
app.py
CHANGED
@@ -148,15 +148,15 @@ async def get_answer_llama3(request: Request ):
|
|
148 |
# print("recived ",text)
|
149 |
proxy=None
|
150 |
|
151 |
-
try:
|
152 |
-
|
153 |
-
except:
|
154 |
-
|
155 |
-
print('proxy ip ', proxy )
|
156 |
-
currtime= time.time()
|
157 |
-
res= ""
|
158 |
|
159 |
-
res = do_ML_LLAMA70b(text,0,
|
160 |
|
161 |
|
162 |
dict={"LLAMA":res}
|
@@ -225,17 +225,21 @@ def do_ML_LLAMA70b_chori(text:str, trycount:int, proxy:str):
|
|
225 |
continue;
|
226 |
except:
|
227 |
print('done gen ')
|
228 |
-
time.sleep(1)
|
229 |
-
div_element = driver.find_elements(By.CLASS_NAME,'md.svelte-9tftx4.chatbot')
|
230 |
-
div_element= div_element[len(div_element)-1]
|
231 |
-
# Extract and print the text content of the div element
|
232 |
-
div_text = div_element.text
|
233 |
-
print(div_text)
|
234 |
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
|
240 |
|
241 |
driver.delete_all_cookies()
|
@@ -244,7 +248,8 @@ def do_ML_LLAMA70b_chori(text:str, trycount:int, proxy:str):
|
|
244 |
|
245 |
|
246 |
|
247 |
-
except:
|
|
|
248 |
driver.delete_all_cookies()
|
249 |
driver.quit()
|
250 |
currtime= time.time()
|
@@ -261,13 +266,12 @@ def do_ML_LLAMA70b(text:str, trycount:int, proxy:str):
|
|
261 |
options.add_argument('-headless')
|
262 |
options.add_argument("start-maximized")
|
263 |
options.add_argument("--ignore-certificate-errors")
|
264 |
-
proxy_port = "8080"
|
265 |
-
proxy_ip= proxy
|
266 |
-
print("pxoxy ip ",proxy_ip)
|
267 |
-
proxy_ip = f"{proxy_ip}:{proxy_port}"
|
268 |
-
print("proxy final ", proxy_ip)
|
269 |
-
options.add_argument(f'--proxy-server=http://{proxy_ip}')
|
270 |
-
|
271 |
service = Service(executable_path=chrome_driver_path)
|
272 |
driver = webdriver.Chrome(options= options,service=service)
|
273 |
driver.get("https://huggingface.co/chat/")
|
@@ -827,4 +831,76 @@ def do_ML_STARCODE(text:str, trycount:int):
|
|
827 |
driver.delete_all_cookies()
|
828 |
driver.quit()
|
829 |
return "Error Occureed"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
830 |
|
|
|
148 |
# print("recived ",text)
|
149 |
proxy=None
|
150 |
|
151 |
+
# try:
|
152 |
+
# proxy = data['proxy']
|
153 |
+
# except:
|
154 |
+
# pass
|
155 |
+
# print('proxy ip ', proxy )
|
156 |
+
# currtime= time.time()
|
157 |
+
# res= ""
|
158 |
|
159 |
+
res = do_ML_LLAMA70b(text,0,'')
|
160 |
|
161 |
|
162 |
dict={"LLAMA":res}
|
|
|
225 |
continue;
|
226 |
except:
|
227 |
print('done gen ')
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
|
229 |
+
while True:
|
230 |
+
|
231 |
+
try:
|
232 |
+
div_element = driver.find_elements(By.CLASS_NAME,'md.svelte-9tftx4.chatbot')
|
233 |
+
div_element= div_element[len(div_element)-1]
|
234 |
+
# Extract and print the text content of the div element
|
235 |
+
div_text = div_element.text
|
236 |
+
print(div_text)
|
237 |
+
driver.delete_all_cookies()
|
238 |
+
driver.quit()
|
239 |
+
print("Lllama chori")
|
240 |
+
return div_text
|
241 |
+
except Exception as e:
|
242 |
+
return "Error Occureed"
|
243 |
|
244 |
|
245 |
driver.delete_all_cookies()
|
|
|
248 |
|
249 |
|
250 |
|
251 |
+
except Exception as e:
|
252 |
+
print(e)
|
253 |
driver.delete_all_cookies()
|
254 |
driver.quit()
|
255 |
currtime= time.time()
|
|
|
266 |
options.add_argument('-headless')
|
267 |
options.add_argument("start-maximized")
|
268 |
options.add_argument("--ignore-certificate-errors")
|
269 |
+
# proxy_port = "8080"
|
270 |
+
# proxy_ip= proxy
|
271 |
+
# print("pxoxy ip ",proxy_ip)
|
272 |
+
# proxy_ip = f"{proxy_ip}:{proxy_port}"
|
273 |
+
# print("proxy final ", proxy_ip)
|
274 |
+
# options.add_argument(f'--proxy-server=http://{proxy_ip}')
|
|
|
275 |
service = Service(executable_path=chrome_driver_path)
|
276 |
driver = webdriver.Chrome(options= options,service=service)
|
277 |
driver.get("https://huggingface.co/chat/")
|
|
|
831 |
driver.delete_all_cookies()
|
832 |
driver.quit()
|
833 |
return "Error Occureed"
|
834 |
+
|
835 |
+
|
836 |
+
@app.post("/chatgpt")
|
837 |
+
async def get_answer_llama3(request: Request ):
|
838 |
+
data = await request.json()
|
839 |
+
msges= data['messages']
|
840 |
+
print("recievoed , ", msges )
|
841 |
+
return do_chat_gpt(msges)
|
842 |
+
|
843 |
+
|
844 |
+
|
845 |
+
|
846 |
+
|
847 |
+
def do_chat_gpt(msges):
|
848 |
+
starttime=time.time()
|
849 |
+
options = ChromeOptions()
|
850 |
+
options.add_argument('--no-sandbox')
|
851 |
+
options.add_argument('-headless')
|
852 |
+
options.add_argument("start-maximized")
|
853 |
+
service = Service(executable_path=chrome_driver_path)
|
854 |
+
driver = webdriver.Chrome(options= options,service=service)
|
855 |
+
driver.get("https://openskyml-pigeon-chat.hf.space/")
|
856 |
+
base=""
|
857 |
+
for message in msges:
|
858 |
+
base += "%s: %s \n" % (message["role"], message["content"])
|
859 |
+
base += "assistant:"
|
860 |
+
print("base ",base)
|
861 |
+
try:
|
862 |
+
while True:
|
863 |
+
curr= time.time()
|
864 |
+
if curr- starttime>20:
|
865 |
+
driver.quit()
|
866 |
+
return "Error -1"
|
867 |
+
try:
|
868 |
+
textarea_element = driver.find_element(By.XPATH,'//textarea[@placeholder="Type a message..."]')
|
869 |
+
for line in base.split('\n'):
|
870 |
+
textarea_element.send_keys(line)
|
871 |
+
textarea_element.send_keys(Keys.SHIFT + Keys.ENTER)
|
872 |
+
time.sleep(0.5)
|
873 |
+
textarea_element.send_keys('\n')
|
874 |
+
break
|
875 |
+
except Exception as e:
|
876 |
+
print(e)
|
877 |
+
time.sleep(0.5)
|
878 |
+
continue
|
879 |
+
while True:
|
880 |
+
curr= time.time()
|
881 |
+
if curr- starttime>175:
|
882 |
+
driver.quit()
|
883 |
+
return "Error -1"
|
884 |
+
try:
|
885 |
+
div_element = driver.find_element(By.CSS_SELECTOR,'div[data-testid="bot"]')
|
886 |
+
text = div_element.text
|
887 |
+
print(text)
|
888 |
+
if text=="":
|
889 |
+
raise ValueError("Empty text")
|
890 |
+
driver.quit()
|
891 |
+
return text
|
892 |
+
except Exception as e:
|
893 |
+
print(e)
|
894 |
+
time.sleep(0.5)
|
895 |
+
except:
|
896 |
+
driver.quit()
|
897 |
+
return "Error"
|
898 |
+
|
899 |
+
|
900 |
+
|
901 |
+
|
902 |
+
|
903 |
+
|
904 |
+
|
905 |
+
|
906 |
|