Viraaj Sawant commited on
Commit
e203921
·
1 Parent(s): 1bf77f2

removed ui

Browse files
Files changed (1) hide show
  1. rl_code_fix_env/ui/app.py +0 -200
rl_code_fix_env/ui/app.py DELETED
@@ -1,200 +0,0 @@
1
- # import streamlit as st
2
- import sys
3
- import os
4
- import streamlit as st
5
-
6
- sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
7
-
8
- from rl_code_fix_env.client import CodeFixerEnv
9
- from rl_code_fix_env.models import CodeFixerAction
10
-
11
- # Set page config
12
- st.set_page_config(page_title="Code Fixer Environment", layout="wide")
13
-
14
- st.title("Code Fixer Agent Environment")
15
-
16
- ENV_URL = os.getenv("ENV_URL", "http://127.0.0.1:8000")
17
-
18
- _WS_ERROR_MARKERS = ("1011", "1006", "keepalive", "timed out", "closed", "connection")
19
-
20
-
21
- def _is_ws_error(exc: Exception) -> bool:
22
- """Return True if the exception looks like a stale WebSocket."""
23
- return any(m in str(exc).lower() for m in _WS_ERROR_MARKERS)
24
-
25
-
26
- def _get_client() -> CodeFixerEnv:
27
- """Return existing client or create a fresh one."""
28
- if "client" not in st.session_state or st.session_state.client is None:
29
- st.session_state.client = CodeFixerEnv(base_url=ENV_URL)
30
- return st.session_state.client
31
-
32
-
33
- def _reset_client() -> CodeFixerEnv:
34
- """Drop the stale client and create a brand-new one."""
35
- try:
36
- if "client" in st.session_state and st.session_state.client is not None:
37
- st.session_state.client.close()
38
- except Exception:
39
- pass
40
- st.session_state.client = CodeFixerEnv(base_url=ENV_URL)
41
- return st.session_state.client
42
-
43
-
44
- # Initialize session state
45
- if "observation" not in st.session_state:
46
- st.session_state.observation = None
47
- if "difficulty_index" not in st.session_state:
48
- st.session_state.difficulty_index = 0 # cycles: easy medium hard
49
-
50
- _DIFFICULTY_CYCLE = ["easy", "medium", "hard"]
51
-
52
- # Ensure client exists on first load
53
- try:
54
- _get_client()
55
- except Exception as e:
56
- st.error(f"Failed to connect to environment: {e}")
57
- st.info(f"Make sure the server is running on {ENV_URL}")
58
-
59
-
60
- # Sidebar for controls
61
- with st.sidebar:
62
- st.header("Controls")
63
- col1, col2 = st.columns(2)
64
-
65
- with col1:
66
- if st.button("Load Task", type="primary"):
67
- idx = st.session_state.difficulty_index
68
- difficulty = _DIFFICULTY_CYCLE[idx % len(_DIFFICULTY_CYCLE)]
69
- try:
70
- result = _get_client().reset()
71
- st.session_state.observation = result.observation
72
- st.session_state.difficulty_index = idx + 1
73
- st.success(f"Loaded **{difficulty}** task!")
74
- st.rerun()
75
- except Exception as e:
76
- if _is_ws_error(e):
77
- try:
78
- result = _reset_client().reset()
79
- st.session_state.observation = result.observation
80
- st.session_state.difficulty_index = idx + 1
81
- st.success(f"Reconnected & loaded **{difficulty}** task!")
82
- st.rerun()
83
- except Exception as e2:
84
- st.error(f"Reconnect failed: {e2}")
85
- else:
86
- st.error(f"Error loading task: {e}")
87
-
88
- with col2:
89
- if st.button("Reset Env"):
90
- try:
91
- result = _get_client().reset()
92
- st.session_state.observation = result.observation
93
- st.success("Environment reset!")
94
- st.rerun()
95
- except Exception as e:
96
- if _is_ws_error(e):
97
- try:
98
- result = _reset_client().reset()
99
- st.session_state.observation = result.observation
100
- st.success("Reconnected & environment reset!")
101
- st.rerun()
102
- except Exception as e2:
103
- st.error(f"Reconnect failed: {e2}")
104
- else:
105
- st.error(f"Error resetting environment: {e}")
106
-
107
-
108
- st.divider()
109
-
110
- if st.session_state.observation:
111
- st.subheader("Environment Status")
112
- obs = st.session_state.observation
113
- st.write(f"**Steps:** {obs.steps}")
114
- st.write(f"**Test Score:** {obs.test_score:.2f} / 1.00")
115
- st.write(f"**Done:** {obs.done}")
116
- st.write(f"**Reward:** {obs.reward}")
117
- else:
118
- st.info("Click 'Load Task' to start a new problem.")
119
-
120
- # Main content area
121
- if st.session_state.observation:
122
- obs = st.session_state.observation
123
-
124
- col1, col2 = st.columns([1, 1])
125
-
126
- with col1:
127
- st.subheader("Current Code")
128
- st.code(obs.code, language="python")
129
-
130
- with col2:
131
- st.subheader("Actions")
132
-
133
- # Action: Apply Patch
134
- st.markdown("### Apply Patch")
135
- patch_text = st.text_area("Enter patch here:", height=200)
136
- if st.button("Apply Patch"):
137
- action = CodeFixerAction(type="apply_patch", payload=patch_text)
138
- try:
139
- result = _get_client().step(action)
140
- st.session_state.observation = result.observation
141
- st.rerun()
142
- except Exception as e:
143
- if _is_ws_error(e):
144
- try:
145
- result = _reset_client().step(action)
146
- st.session_state.observation = result.observation
147
- st.rerun()
148
- except Exception as e2:
149
- st.error(f"Reconnect failed: {e2}")
150
- else:
151
- st.error(f"Error applying patch: {e}")
152
-
153
- st.divider()
154
-
155
- # Action: Run Tests
156
- st.markdown("### Run Tests")
157
- if st.button("Execute Tests"):
158
- action = CodeFixerAction(type="run_tests")
159
- try:
160
- result = _get_client().step(action)
161
- st.session_state.observation = result.observation
162
- st.rerun()
163
- except Exception as e:
164
- if _is_ws_error(e):
165
- try:
166
- result = _reset_client().step(action)
167
- st.session_state.observation = result.observation
168
- st.rerun()
169
- except Exception as e2:
170
- st.error(f"Reconnect failed: {e2}")
171
- else:
172
- st.error(f"Error running tests: {e}")
173
-
174
- st.divider()
175
-
176
- # Action: Get Logs
177
- st.markdown("### Get Logs")
178
- if st.button("Fetch Logs"):
179
- action = CodeFixerAction(type="get_logs")
180
- try:
181
- result = _get_client().step(action)
182
- st.session_state.observation = result.observation
183
- st.rerun()
184
- except Exception as e:
185
- if _is_ws_error(e):
186
- try:
187
- result = _reset_client().step(action)
188
- st.session_state.observation = result.observation
189
- st.rerun()
190
- except Exception as e2:
191
- st.error(f"Reconnect failed: {e2}")
192
- else:
193
- st.error(f"Error getting logs: {e}")
194
-
195
- # Display Logs
196
- if obs.logs:
197
- st.subheader("Logs")
198
- st.text_area("Output Logs", obs.logs, height=200, disabled=True)
199
-
200
-