Spaces:
Running
Running
Tecnhotron
commited on
Commit
·
a3d3eec
1
Parent(s):
334257b
First
Browse files
__pycache__/computer_control_helper.cpython-313.pyc
ADDED
Binary file (28.8 kB). View file
|
|
__pycache__/streaming.cpython-313.pyc
ADDED
Binary file (12.7 kB). View file
|
|
__pycache__/test_api.cpython-313-pytest-8.3.5.pyc
DELETED
Binary file (16.2 kB)
|
|
api.py
CHANGED
@@ -20,6 +20,7 @@ from selenium.webdriver.support.ui import WebDriverWait
|
|
20 |
from selenium.webdriver.support import expected_conditions as EC
|
21 |
from selenium.common.exceptions import TimeoutException, NoSuchElementException, StaleElementReferenceException
|
22 |
import random
|
|
|
23 |
from streaming import StreamProcessor, create_streaming_response, StreamConfig, StreamingResponseGenerator
|
24 |
import base64
|
25 |
|
@@ -170,12 +171,14 @@ class DriverManager:
|
|
170 |
# Randomly choose between F5 and FN+F5
|
171 |
if random.random() > 0.5:
|
172 |
logger.info("Using F5 key")
|
173 |
-
|
174 |
-
body.send_keys(Keys.F5)
|
175 |
else:
|
176 |
logger.info("Using FN+F5 key combination")
|
177 |
-
|
178 |
-
|
|
|
|
|
|
|
179 |
|
180 |
# Add random delay to simulate human behavior
|
181 |
sleep_time = random.uniform(0.5, 2.0)
|
@@ -428,6 +431,35 @@ If you cannot find the checkbox, respond with "No checkbox found".
|
|
428 |
logger.error(f"Error executing _select_model in executor: {e_exec}", exc_info=True)
|
429 |
raise ModelSelectionError(f"Failed to select model {model_id} due to executor error: {e_exec}") from e_exec
|
430 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
431 |
def generate_reload_button_location(self, driver: Driver) -> str:
|
432 |
# This function is not used by the refined captcha logic, but keeping it as it might be used elsewhere.
|
433 |
logger.info("Generating reload button location with Gemini")
|
@@ -472,12 +504,13 @@ If you cannot find the reload button, respond with "No reload button found".
|
|
472 |
if "No reload button found" in full_response_text:
|
473 |
logger.info("AI did not find reload button, performing manual F5 and FN+F5 reloads.")
|
474 |
try:
|
475 |
-
|
476 |
-
# F5 reload simulation
|
477 |
-
body.send_keys(Keys.F5)
|
478 |
time.sleep(0.5)
|
479 |
-
|
480 |
-
|
|
|
|
|
|
|
481 |
time.sleep(0.5)
|
482 |
# Capture screenshot after manual reload
|
483 |
png2 = driver.get_screenshot_as_png()
|
|
|
20 |
from selenium.webdriver.support import expected_conditions as EC
|
21 |
from selenium.common.exceptions import TimeoutException, NoSuchElementException, StaleElementReferenceException
|
22 |
import random
|
23 |
+
import pyautogui
|
24 |
from streaming import StreamProcessor, create_streaming_response, StreamConfig, StreamingResponseGenerator
|
25 |
import base64
|
26 |
|
|
|
171 |
# Randomly choose between F5 and FN+F5
|
172 |
if random.random() > 0.5:
|
173 |
logger.info("Using F5 key")
|
174 |
+
pyautogui.press('f5')
|
|
|
175 |
else:
|
176 |
logger.info("Using FN+F5 key combination")
|
177 |
+
pyautogui.keyDown('ctrl')
|
178 |
+
time.sleep(0.3)
|
179 |
+
pyautogui.press('f5')
|
180 |
+
time.sleep(0.3)
|
181 |
+
pyautogui.keyUp('ctrl')
|
182 |
|
183 |
# Add random delay to simulate human behavior
|
184 |
sleep_time = random.uniform(0.5, 2.0)
|
|
|
431 |
logger.error(f"Error executing _select_model in executor: {e_exec}", exc_info=True)
|
432 |
raise ModelSelectionError(f"Failed to select model {model_id} due to executor error: {e_exec}") from e_exec
|
433 |
|
434 |
+
async def _retry_with_reload(self, driver: Driver, model_id: str):
|
435 |
+
"""Handle ModelSelectionError by reloading and retrying once"""
|
436 |
+
try:
|
437 |
+
# Manual reload simulation
|
438 |
+
pyautogui.press('f5')
|
439 |
+
time.sleep(0.5)
|
440 |
+
# Hard refresh (Ctrl+F5) - simulates FN+F5 behavior
|
441 |
+
pyautogui.keyDown('ctrl')
|
442 |
+
time.sleep(0.3)
|
443 |
+
pyautogui.press('f5')
|
444 |
+
time.sleep(0.3)
|
445 |
+
pyautogui.keyUp('ctrl')
|
446 |
+
|
447 |
+
# Wait for page reload
|
448 |
+
WebDriverWait(driver, config.page_load_wait_after_refresh_seconds).until(
|
449 |
+
EC.presence_of_element_located((By.XPATH, "//input[@placeholder='Search models' and @cmdk-input]"))
|
450 |
+
)
|
451 |
+
|
452 |
+
# Retry model selection
|
453 |
+
await self._select_model(model_id)
|
454 |
+
|
455 |
+
except Exception as reload_err:
|
456 |
+
logger.error(f"Reload and retry failed: {reload_err}", exc_info=True)
|
457 |
+
# Capture screenshot after failed reload
|
458 |
+
png = driver.get_screenshot_as_png()
|
459 |
+
b64 = base64.b64encode(png).decode('utf-8')
|
460 |
+
logger.error(f"Screenshot base64 after failed reload: {b64}")
|
461 |
+
raise ModelSelectionError(f"Failed after reload attempt: {reload_err}") from reload_err
|
462 |
+
|
463 |
def generate_reload_button_location(self, driver: Driver) -> str:
|
464 |
# This function is not used by the refined captcha logic, but keeping it as it might be used elsewhere.
|
465 |
logger.info("Generating reload button location with Gemini")
|
|
|
504 |
if "No reload button found" in full_response_text:
|
505 |
logger.info("AI did not find reload button, performing manual F5 and FN+F5 reloads.")
|
506 |
try:
|
507 |
+
pyautogui.press('f5')
|
|
|
|
|
508 |
time.sleep(0.5)
|
509 |
+
pyautogui.keyDown('ctrl')
|
510 |
+
time.sleep(0.3)
|
511 |
+
pyautogui.press('f5')
|
512 |
+
time.sleep(0.3)
|
513 |
+
pyautogui.keyUp('ctrl')
|
514 |
time.sleep(0.5)
|
515 |
# Capture screenshot after manual reload
|
516 |
png2 = driver.get_screenshot_as_png()
|
downloaded_files/driver_fixing.lock
ADDED
File without changes
|
downloaded_files/pipfinding.lock
ADDED
File without changes
|
downloaded_files/pyautogui.lock
ADDED
File without changes
|