Protect environ variables
Browse files- components.py +5 -4
components.py
CHANGED
|
@@ -111,7 +111,9 @@ class AITask(TaskComponent):
|
|
| 111 |
class CodeTask(TaskComponent):
|
| 112 |
name = "Code Task"
|
| 113 |
|
| 114 |
-
def __init__(
|
|
|
|
|
|
|
| 115 |
super().__init__(id_, value, visible)
|
| 116 |
self._initial_code_value = code_value
|
| 117 |
|
|
@@ -143,9 +145,7 @@ class CodeTask(TaskComponent):
|
|
| 143 |
error_message = gr.HighlightedText(value=None, visible=False)
|
| 144 |
|
| 145 |
self.input = gr.Textbox(
|
| 146 |
-
label="Input",
|
| 147 |
-
interactive=True,
|
| 148 |
-
value=self._initial_value
|
| 149 |
)
|
| 150 |
with gr.Column():
|
| 151 |
self.output = gr.Textbox(
|
|
@@ -269,6 +269,7 @@ class CodeTask(TaskComponent):
|
|
| 269 |
subprocess.check_call([sys.executable, "-m", "pip", "install", p])
|
| 270 |
|
| 271 |
function = function.strip()
|
|
|
|
| 272 |
exec(function, locals())
|
| 273 |
# Looking for the last defined function
|
| 274 |
for var in reversed(locals().values()):
|
|
|
|
| 111 |
class CodeTask(TaskComponent):
|
| 112 |
name = "Code Task"
|
| 113 |
|
| 114 |
+
def __init__(
|
| 115 |
+
self, id_: int, value: str = "", visible: bool = False, code_value: str = ""
|
| 116 |
+
):
|
| 117 |
super().__init__(id_, value, visible)
|
| 118 |
self._initial_code_value = code_value
|
| 119 |
|
|
|
|
| 145 |
error_message = gr.HighlightedText(value=None, visible=False)
|
| 146 |
|
| 147 |
self.input = gr.Textbox(
|
| 148 |
+
label="Input", interactive=True, value=self._initial_value
|
|
|
|
|
|
|
| 149 |
)
|
| 150 |
with gr.Column():
|
| 151 |
self.output = gr.Textbox(
|
|
|
|
| 269 |
subprocess.check_call([sys.executable, "-m", "pip", "install", p])
|
| 270 |
|
| 271 |
function = function.strip()
|
| 272 |
+
function = f"import os\nos.environ = {{}}\n\n{function}"
|
| 273 |
exec(function, locals())
|
| 274 |
# Looking for the last defined function
|
| 275 |
for var in reversed(locals().values()):
|