Spaces:
Runtime error
Runtime error
prashasti commited on
Commit ·
f2402e7
1
Parent(s): 1733506
changes
Browse files
ui.py
CHANGED
|
@@ -1,48 +1,51 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
-
BASE_URL = "http://localhost:8000"
|
| 5 |
|
| 6 |
current_logs = []
|
| 7 |
current_actions = []
|
| 8 |
|
| 9 |
|
| 10 |
def reset_env(task):
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
"Environment reset",
|
| 22 |
-
"Running..."
|
| 23 |
-
)
|
| 24 |
|
| 25 |
|
| 26 |
def step_env(action):
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
data = res.json()
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
"\n".join(current_actions),
|
| 44 |
-
status
|
| 45 |
-
)
|
| 46 |
|
| 47 |
|
| 48 |
def format_logs(logs):
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
import requests
|
| 5 |
|
| 6 |
+
BASE_URL = os.getenv("SPACE_URL", "http://localhost:8000")
|
| 7 |
|
| 8 |
current_logs = []
|
| 9 |
current_actions = []
|
| 10 |
|
| 11 |
|
| 12 |
def reset_env(task):
|
| 13 |
+
try:
|
| 14 |
+
res = requests.post(f"{BASE_URL}/reset", json={"task": task})
|
| 15 |
+
res.raise_for_status()
|
| 16 |
|
| 17 |
+
data = res.json()
|
| 18 |
+
obs = data["observation"]
|
| 19 |
|
| 20 |
+
return (
|
| 21 |
+
format_logs(obs.get("logs", [])),
|
| 22 |
+
"Environment reset",
|
| 23 |
+
"Running...",
|
| 24 |
+
)
|
| 25 |
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return ("Error occurred", str(e), "Failed", None)
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
def step_env(action):
|
| 31 |
+
try:
|
| 32 |
+
res = requests.post(f"{BASE_URL}/step", json={"action": action})
|
| 33 |
+
res.raise_for_status()
|
| 34 |
|
| 35 |
+
data = res.json()
|
|
|
|
| 36 |
|
| 37 |
+
obs = data["observation"]
|
| 38 |
+
reward = data["reward"]
|
| 39 |
+
done = data["done"]
|
| 40 |
|
| 41 |
+
return (
|
| 42 |
+
format_logs(obs.get("logs", [])),
|
| 43 |
+
f"{action} → {reward}",
|
| 44 |
+
"Done" if done else "Running",
|
| 45 |
+
)
|
| 46 |
|
| 47 |
+
except Exception as e:
|
| 48 |
+
return ("Error occurred", str(e), "Failed", None)
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
def format_logs(logs):
|