Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
|
|
|
| 3 |
|
| 4 |
# Install BrowserGym dependencies before running the main application
|
| 5 |
def install_browsergym():
|
|
@@ -7,23 +8,38 @@ def install_browsergym():
|
|
| 7 |
print("Installing BrowserGym dependencies...")
|
| 8 |
subprocess.run("cd BrowserGym && make install", shell=True, check=True)
|
| 9 |
print("BrowserGym installation completed successfully")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
except subprocess.CalledProcessError as e:
|
| 11 |
print(f"Error installing BrowserGym: {e}")
|
| 12 |
raise
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 16 |
-
browsergym_path = os.path.join(current_dir, "BrowserGym")
|
| 17 |
-
if "PYTHONPATH" in os.environ:
|
| 18 |
-
os.environ["PYTHONPATH"] = f"{browsergym_path}:{os.environ['PYTHONPATH']}"
|
| 19 |
-
else:
|
| 20 |
-
os.environ["PYTHONPATH"] = browsergym_path
|
| 21 |
-
print(f"Updated PYTHONPATH: {os.environ['PYTHONPATH']}")
|
| 22 |
-
|
| 23 |
-
|
| 24 |
install_browsergym()
|
| 25 |
|
| 26 |
-
import
|
| 27 |
import logging
|
| 28 |
import gradio as gr
|
| 29 |
import openai
|
|
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
| 3 |
+
import sys
|
| 4 |
|
| 5 |
# Install BrowserGym dependencies before running the main application
|
| 6 |
def install_browsergym():
|
|
|
|
| 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 browsergym.core
|
| 29 |
+
print("BrowserGym successfully imported")
|
| 30 |
+
except ImportError as e:
|
| 31 |
+
print(f"BrowserGym import verification failed: {e}")
|
| 32 |
+
print(f"Current sys.path: {sys.path}")
|
| 33 |
+
raise
|
| 34 |
+
|
| 35 |
except subprocess.CalledProcessError as e:
|
| 36 |
print(f"Error installing BrowserGym: {e}")
|
| 37 |
raise
|
| 38 |
|
| 39 |
+
# Install BrowserGym first
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
install_browsergym()
|
| 41 |
|
| 42 |
+
# Now import the rest of the modules
|
| 43 |
import logging
|
| 44 |
import gradio as gr
|
| 45 |
import openai
|