Update app.py
Browse files
app.py
CHANGED
|
@@ -73,14 +73,80 @@ app.add_middleware(
|
|
| 73 |
# data_frame = pd.read_csv('data.csv')
|
| 74 |
|
| 75 |
from selenium.webdriver.common.by import By
|
|
|
|
| 76 |
|
| 77 |
@app.on_event("startup")
|
| 78 |
async def startup_event():
|
| 79 |
print("on startup")
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
t = threading.Thread(target=makeqimg)
|
| 83 |
-
t.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
from queue import Queue
|
| 86 |
chatq = Queue()
|
|
@@ -166,24 +232,12 @@ def do_ML(id:str,text:str,host:str, trycount:int,temperature:float):
|
|
| 166 |
|
| 167 |
try:
|
| 168 |
starttime=time.time()
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
driver= chatq.get()
|
| 177 |
-
# chatq.pop()[0]
|
| 178 |
-
t = threading.Thread(target=makeqchat)
|
| 179 |
-
t.start()
|
| 180 |
-
break;
|
| 181 |
-
except Exception as error:
|
| 182 |
-
print("Error in popping ", error )
|
| 183 |
-
t = threading.Thread(target=makeqchat)
|
| 184 |
-
t.start()
|
| 185 |
-
time.sleep(0.5)
|
| 186 |
-
|
| 187 |
if temperature>=0 and temperature<=2:
|
| 188 |
try:
|
| 189 |
print("setting temperature ",temperature)
|
|
@@ -318,27 +372,12 @@ def do_ML2(id:str,text:str,host:str, trycount:int):
|
|
| 318 |
try:
|
| 319 |
starttime=time.time()
|
| 320 |
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
currtime= time.time()
|
| 328 |
-
if(currtime>starttime+10):
|
| 329 |
-
return "Error"
|
| 330 |
-
|
| 331 |
-
driver= imgq.get()
|
| 332 |
-
# chatq.pop()[0]
|
| 333 |
-
t = threading.Thread(target=makeqimg)
|
| 334 |
-
t.start()
|
| 335 |
-
break
|
| 336 |
-
except Exception as error:
|
| 337 |
-
print("Error in popping ", error )
|
| 338 |
-
t = threading.Thread(target=makeqimg)
|
| 339 |
-
t.start()
|
| 340 |
-
time.sleep(0.5)
|
| 341 |
-
|
| 342 |
while True:
|
| 343 |
currtime= time.time()
|
| 344 |
if(currtime>starttime+10):
|
|
|
|
| 73 |
# data_frame = pd.read_csv('data.csv')
|
| 74 |
|
| 75 |
from selenium.webdriver.common.by import By
|
| 76 |
+
from pymongo.mongo_client import MongoClient
|
| 77 |
|
| 78 |
@app.on_event("startup")
|
| 79 |
async def startup_event():
|
| 80 |
print("on startup")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
# t = threading.Thread(target=makeqimg)
|
| 84 |
+
# t.start()
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
mycol = None
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
@app.post("/url")
|
| 94 |
+
async def get_url(request: Request ):
|
| 95 |
+
return "k"
|
| 96 |
+
|
| 97 |
+
# data = await request.json()
|
| 98 |
+
# text = data['url']
|
| 99 |
+
# mongo_url=text
|
| 100 |
+
# print("mongo url ",text)
|
| 101 |
+
# global mycol
|
| 102 |
+
# if mycol==None:
|
| 103 |
+
# myclient = MongoClient(mongo_url)
|
| 104 |
+
|
| 105 |
+
# try:
|
| 106 |
+
# myclient.admin.command('ping')
|
| 107 |
+
# print("Pinged your deployment. You successfully connected to MongoDB!")
|
| 108 |
+
# except Exception as e:
|
| 109 |
+
# print(e)
|
| 110 |
+
|
| 111 |
+
# mydb = myclient['open-ai-api-keys']
|
| 112 |
+
|
| 113 |
+
# mycol= mydb['key']
|
| 114 |
+
# extract()
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def extract():
|
| 120 |
+
options = ChromeOptions()
|
| 121 |
+
options.add_argument('--no-sandbox')
|
| 122 |
+
options.add_argument('-headless')
|
| 123 |
+
service = Service()
|
| 124 |
+
driver = webdriver.Chrome(options= options,service=service)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
global mycol
|
| 128 |
+
# global driver
|
| 129 |
+
|
| 130 |
+
if True:
|
| 131 |
+
# time.sleep(60)
|
| 132 |
+
try:
|
| 133 |
+
driver.get("https://talkai.info/chat/")
|
| 134 |
+
element = driver.find_element(By.CSS_SELECTOR,".chat")
|
| 135 |
+
api_key = element.get_attribute("data-api-key")
|
| 136 |
+
dict={"key":"open-ai"}
|
| 137 |
+
mycol.delete_one(dict)
|
| 138 |
+
dict={"key":"open-ai","value":api_key}
|
| 139 |
+
mycol.insert_one(dict)
|
| 140 |
+
print(api_key)
|
| 141 |
+
driver.delete_all_cookies()
|
| 142 |
+
driver.quit()
|
| 143 |
+
|
| 144 |
+
except Exception as e:
|
| 145 |
+
print('error in extract ',e)
|
| 146 |
+
pass
|
| 147 |
+
# time.sleep(60)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
|
| 151 |
from queue import Queue
|
| 152 |
chatq = Queue()
|
|
|
|
| 232 |
|
| 233 |
try:
|
| 234 |
starttime=time.time()
|
| 235 |
+
options = ChromeOptions()
|
| 236 |
+
options.add_argument('--no-sandbox')
|
| 237 |
+
options.add_argument('-headless')
|
| 238 |
+
service = Service()
|
| 239 |
+
driver = webdriver.Chrome(options= options,service=service)
|
| 240 |
+
driver.get("https://talkai.info/chat/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
if temperature>=0 and temperature<=2:
|
| 242 |
try:
|
| 243 |
print("setting temperature ",temperature)
|
|
|
|
| 372 |
try:
|
| 373 |
starttime=time.time()
|
| 374 |
|
| 375 |
+
options = ChromeOptions()
|
| 376 |
+
options.add_argument('--no-sandbox')
|
| 377 |
+
options.add_argument('-headless')
|
| 378 |
+
service = Service()
|
| 379 |
+
driver = webdriver.Chrome(options= options,service=service)
|
| 380 |
+
driver.get("https://talkai.info/image/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
while True:
|
| 382 |
currtime= time.time()
|
| 383 |
if(currtime>starttime+10):
|