Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -222,6 +222,55 @@ class App:
|
|
| 222 |
else:
|
| 223 |
return None, f"Error: Failed to parse action from NLP response\n"
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
def run(self):
|
| 226 |
self._print_welcome_message()
|
| 227 |
|
|
@@ -261,30 +310,17 @@ class App:
|
|
| 261 |
if system_message:
|
| 262 |
print(system_message)
|
| 263 |
|
| 264 |
-
def build_app(self):
|
| 265 |
-
with gr.Blocks() as demo:
|
| 266 |
-
for component in self.app_state["components"]:
|
| 267 |
-
component_type = component["type"]
|
| 268 |
-
properties = component["properties"]
|
| 269 |
-
|
| 270 |
-
if component_type == "Button":
|
| 271 |
-
gr.Button(value=properties["label"], variant="primary")
|
| 272 |
-
elif component_type == "Text Input":
|
| 273 |
-
gr.Textbox(label=properties["placeholder"])
|
| 274 |
-
elif component_type == "Image":
|
| 275 |
-
gr.Image(label=properties["alt"])
|
| 276 |
-
elif component_type == "Dropdown":
|
| 277 |
-
gr.Dropdown(choices=properties["choices"], label="Dropdown")
|
| 278 |
-
|
| 279 |
-
return demo
|
| 280 |
-
|
| 281 |
def launch_app(self):
|
| 282 |
demo = self.build_app()
|
| 283 |
demo.launch()
|
| 284 |
|
| 285 |
def main():
|
| 286 |
-
|
| 287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
|
| 289 |
if __name__ == "__main__":
|
| 290 |
main()
|
|
|
|
| 222 |
else:
|
| 223 |
return None, f"Error: Failed to parse action from NLP response\n"
|
| 224 |
|
| 225 |
+
def build_app(self):
|
| 226 |
+
with gr.Blocks() as demo:
|
| 227 |
+
for component in self.app_state["components"]:
|
| 228 |
+
component_type = component["type"]
|
| 229 |
+
properties = component["properties"]
|
| 230 |
+
|
| 231 |
+
if component_type == "Button":
|
| 232 |
+
gr.Button(value=properties["label"], variant="primary")
|
| 233 |
+
elif component_type == "Text Input":
|
| 234 |
+
gr.Textbox(label=properties["placeholder"])
|
| 235 |
+
elif component_type == "Image":
|
| 236 |
+
gr.Image(label=properties["alt"])
|
| 237 |
+
elif component_type == "Dropdown":
|
| 238 |
+
gr.Dropdown(choices=properties["choices"], label="Dropdown")
|
| 239 |
+
|
| 240 |
+
with gr.Tab("Components"):
|
| 241 |
+
gr.Markdown("## Available Components")
|
| 242 |
+
component_type = gr.Dropdown(label="Component Type", choices=list(self.components_registry.keys()))
|
| 243 |
+
properties = gr.JSON(label="Properties")
|
| 244 |
+
add_component_button = gr.Button("Add Component")
|
| 245 |
+
add_component_button.click(
|
| 246 |
+
self.add_component,
|
| 247 |
+
inputs=[component_type, properties],
|
| 248 |
+
outputs=[]
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
with gr.Tab("NLP Models"):
|
| 252 |
+
gr.Markdown("## Available NLP Models")
|
| 253 |
+
model_index = gr.Slider(label="Model Index", minimum=0, maximum=len(self.nlp_model_names)-1, step=1)
|
| 254 |
+
input_text = gr.Textbox(label="Input Text")
|
| 255 |
+
get_nlp_response_button = gr.Button("Get NLP Response")
|
| 256 |
+
get_nlp_response_button.click(
|
| 257 |
+
self.get_nlp_response,
|
| 258 |
+
inputs=[input_text, model_index],
|
| 259 |
+
outputs="text"
|
| 260 |
+
|
| 261 |
+
with gr.Tab("Terminal"):
|
| 262 |
+
gr.Markdown("## Terminal")
|
| 263 |
+
terminal_input = gr.Textbox(label="Input")
|
| 264 |
+
terminal_output = gr.Textbox(label="Output")
|
| 265 |
+
run_terminal_command_button = gr.Button("Run Command")
|
| 266 |
+
run_terminal_command_button.click(
|
| 267 |
+
self.run_terminal_command,
|
| 268 |
+
inputs=[terminal_input],
|
| 269 |
+
outputs=[terminal_output]
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
return demo
|
| 273 |
+
|
| 274 |
def run(self):
|
| 275 |
self._print_welcome_message()
|
| 276 |
|
|
|
|
| 310 |
if system_message:
|
| 311 |
print(system_message)
|
| 312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
def launch_app(self):
|
| 314 |
demo = self.build_app()
|
| 315 |
demo.launch()
|
| 316 |
|
| 317 |
def main():
|
| 318 |
+
try:
|
| 319 |
+
app = App()
|
| 320 |
+
demo = app.build_app()
|
| 321 |
+
demo.launch()
|
| 322 |
+
except Exception as e:
|
| 323 |
+
print(f"Error launching app: {e}")
|
| 324 |
|
| 325 |
if __name__ == "__main__":
|
| 326 |
main()
|