Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,7 +38,7 @@ load_dotenv(override=True)
|
|
| 38 |
# CONFIGURATION & CONSTANTS
|
| 39 |
# -----------------------------------------------------------------------------
|
| 40 |
|
| 41 |
-
E2B_API_KEY = os.getenv("
|
| 42 |
HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_API_KEY")
|
| 43 |
if HF_TOKEN:
|
| 44 |
login(token=HF_TOKEN)
|
|
@@ -432,6 +432,11 @@ class E2BVisionAgent(CodeAgent):
|
|
| 432 |
def drag_and_drop(x1: int, y1: int, x2: int, y2: int) -> str:
|
| 433 |
"""
|
| 434 |
Clicks [x1, y1], drags mouse to [x2, y2], then release click.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
"""
|
| 436 |
self.desktop.drag([x1, y1], [x2, y2])
|
| 437 |
message = f"Dragged and dropped from [{x1}, {y1}] to [{x2}, {y2}]"
|
|
@@ -458,6 +463,8 @@ class E2BVisionAgent(CodeAgent):
|
|
| 458 |
def wait(seconds: float) -> str:
|
| 459 |
"""
|
| 460 |
Waits for the specified number of seconds.
|
|
|
|
|
|
|
| 461 |
"""
|
| 462 |
time.sleep(seconds)
|
| 463 |
self.logger.log(f"Waited for {seconds} seconds")
|
|
@@ -467,6 +474,8 @@ class E2BVisionAgent(CodeAgent):
|
|
| 467 |
def open_url(url: str) -> str:
|
| 468 |
"""
|
| 469 |
Directly opens a browser with the specified url.
|
|
|
|
|
|
|
| 470 |
"""
|
| 471 |
if not url.startswith(("http://", "https://")):
|
| 472 |
url = "https://" + url
|
|
@@ -480,6 +489,8 @@ class E2BVisionAgent(CodeAgent):
|
|
| 480 |
def find_on_page_ctrl_f(search_string: str) -> str:
|
| 481 |
"""
|
| 482 |
Scroll the browser viewport to the first occurrence of the search string (Ctrl+F).
|
|
|
|
|
|
|
| 483 |
"""
|
| 484 |
self.desktop.press(["ctrl", "f"])
|
| 485 |
time.sleep(0.3)
|
|
@@ -780,7 +791,6 @@ def initialize_session(interactive_mode, browser_uuid):
|
|
| 780 |
return update_html(interactive_mode, browser_uuid), browser_uuid
|
| 781 |
|
| 782 |
class EnrichedGradioUI(GradioUI):
|
| 783 |
-
# REMOVED @spaces.GPU from here to prevent pickling the E2B Sandbox (which has locks)
|
| 784 |
def interact_with_agent(
|
| 785 |
self,
|
| 786 |
task_input,
|
|
|
|
| 38 |
# CONFIGURATION & CONSTANTS
|
| 39 |
# -----------------------------------------------------------------------------
|
| 40 |
|
| 41 |
+
E2B_API_KEY = os.getenv("E2B_API_KEY")
|
| 42 |
HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_API_KEY")
|
| 43 |
if HF_TOKEN:
|
| 44 |
login(token=HF_TOKEN)
|
|
|
|
| 432 |
def drag_and_drop(x1: int, y1: int, x2: int, y2: int) -> str:
|
| 433 |
"""
|
| 434 |
Clicks [x1, y1], drags mouse to [x2, y2], then release click.
|
| 435 |
+
Args:
|
| 436 |
+
x1: The x coordinate of the start position.
|
| 437 |
+
y1: The y coordinate of the start position.
|
| 438 |
+
x2: The x coordinate of the end position.
|
| 439 |
+
y2: The y coordinate of the end position.
|
| 440 |
"""
|
| 441 |
self.desktop.drag([x1, y1], [x2, y2])
|
| 442 |
message = f"Dragged and dropped from [{x1}, {y1}] to [{x2}, {y2}]"
|
|
|
|
| 463 |
def wait(seconds: float) -> str:
|
| 464 |
"""
|
| 465 |
Waits for the specified number of seconds.
|
| 466 |
+
Args:
|
| 467 |
+
seconds: The duration to wait in seconds.
|
| 468 |
"""
|
| 469 |
time.sleep(seconds)
|
| 470 |
self.logger.log(f"Waited for {seconds} seconds")
|
|
|
|
| 474 |
def open_url(url: str) -> str:
|
| 475 |
"""
|
| 476 |
Directly opens a browser with the specified url.
|
| 477 |
+
Args:
|
| 478 |
+
url: The website URL to open.
|
| 479 |
"""
|
| 480 |
if not url.startswith(("http://", "https://")):
|
| 481 |
url = "https://" + url
|
|
|
|
| 489 |
def find_on_page_ctrl_f(search_string: str) -> str:
|
| 490 |
"""
|
| 491 |
Scroll the browser viewport to the first occurrence of the search string (Ctrl+F).
|
| 492 |
+
Args:
|
| 493 |
+
search_string: The text to search for on the page.
|
| 494 |
"""
|
| 495 |
self.desktop.press(["ctrl", "f"])
|
| 496 |
time.sleep(0.3)
|
|
|
|
| 791 |
return update_html(interactive_mode, browser_uuid), browser_uuid
|
| 792 |
|
| 793 |
class EnrichedGradioUI(GradioUI):
|
|
|
|
| 794 |
def interact_with_agent(
|
| 795 |
self,
|
| 796 |
task_input,
|