Spaces:
Sleeping
Sleeping
Update app_.py
Browse files
app_.py
CHANGED
|
@@ -2,60 +2,6 @@ import os
|
|
| 2 |
import subprocess
|
| 3 |
import sys
|
| 4 |
|
| 5 |
-
# Install BrowserGym dependencies before running the main application
|
| 6 |
-
def install_browsergym():
|
| 7 |
-
try:
|
| 8 |
-
print("Installing BrowserGym dependencies...")
|
| 9 |
-
subprocess.run("cd BrowserGym && make install", shell=True, check=True)
|
| 10 |
-
print("BrowserGym installation completed successfully")
|
| 11 |
-
|
| 12 |
-
# Add BrowserGym directory to sys.path directly
|
| 13 |
-
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 14 |
-
browsergym_path = os.path.join(current_dir, "BrowserGym")
|
| 15 |
-
if browsergym_path not in sys.path:
|
| 16 |
-
sys.path.insert(0, browsergym_path)
|
| 17 |
-
print(f"Added BrowserGym to sys.path: {browsergym_path}")
|
| 18 |
-
|
| 19 |
-
# Also set PYTHONPATH environment variable for child processes
|
| 20 |
-
if "PYTHONPATH" in os.environ:
|
| 21 |
-
os.environ["PYTHONPATH"] = f"{browsergym_path}:{os.environ['PYTHONPATH']}"
|
| 22 |
-
else:
|
| 23 |
-
os.environ["PYTHONPATH"] = browsergym_path
|
| 24 |
-
print(f"Updated PYTHONPATH: {os.environ['PYTHONPATH']}")
|
| 25 |
-
|
| 26 |
-
# Verify BrowserGym is importable
|
| 27 |
-
try:
|
| 28 |
-
import importlib.util
|
| 29 |
-
|
| 30 |
-
# Try to import HighLevelActionSet
|
| 31 |
-
spec = importlib.util.find_spec("browsergym.core.action.highlevel")
|
| 32 |
-
if spec is None:
|
| 33 |
-
print("Module browsergym.core.action.highlevel not found")
|
| 34 |
-
else:
|
| 35 |
-
module = importlib.util.module_from_spec(spec)
|
| 36 |
-
spec.loader.exec_module(module)
|
| 37 |
-
HighLevelActionSet = getattr(module, "HighLevelActionSet")
|
| 38 |
-
print('good!!')
|
| 39 |
-
from browsergym.core.action.highlevel import HighLevelActionSet
|
| 40 |
-
from browsergym.utils.obs import (
|
| 41 |
-
flatten_axtree_to_str,
|
| 42 |
-
flatten_dom_to_str,
|
| 43 |
-
prune_html,
|
| 44 |
-
)
|
| 45 |
-
from browsergym.experiments import Agent
|
| 46 |
-
print("BrowserGym successfully imported")
|
| 47 |
-
except ImportError as e:
|
| 48 |
-
print(f"BrowserGym import verification failed: {e}")
|
| 49 |
-
print(f"Current sys.path: {sys.path}")
|
| 50 |
-
raise
|
| 51 |
-
|
| 52 |
-
except subprocess.CalledProcessError as e:
|
| 53 |
-
print(f"Error installing BrowserGym: {e}")
|
| 54 |
-
raise
|
| 55 |
-
|
| 56 |
-
# Install BrowserGym first
|
| 57 |
-
install_browsergym()
|
| 58 |
-
|
| 59 |
# Now import the rest of the modules
|
| 60 |
import logging
|
| 61 |
import gradio as gr
|
|
|
|
| 2 |
import subprocess
|
| 3 |
import sys
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
# Now import the rest of the modules
|
| 6 |
import logging
|
| 7 |
import gradio as gr
|