Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -199,19 +199,8 @@ class App:
|
|
| 199 |
|
| 200 |
def build_app(self):
|
| 201 |
with gr.Blocks() as demo:
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
properties = component["properties"]
|
| 205 |
-
|
| 206 |
-
if component_type == "Button":
|
| 207 |
-
gr.Button(value=properties["label"], variant="primary")
|
| 208 |
-
elif component_type == "Text Input":
|
| 209 |
-
gr.Textbox(label=properties["placeholder"])
|
| 210 |
-
elif component_type == "Image":
|
| 211 |
-
gr.Image(label=properties["alt"])
|
| 212 |
-
elif component_type == "Dropdown":
|
| 213 |
-
gr.Dropdown(choices=properties["choices"], label="Dropdown")
|
| 214 |
-
|
| 215 |
with gr.Tab("Terminal"):
|
| 216 |
gr.Markdown("## Terminal")
|
| 217 |
terminal_input = gr.Textbox(label="Input")
|
|
@@ -222,7 +211,6 @@ class App:
|
|
| 222 |
inputs=[terminal_input],
|
| 223 |
outputs=[terminal_output]
|
| 224 |
)
|
| 225 |
-
|
| 226 |
with gr.Tab("NLP Models"):
|
| 227 |
gr.Markdown("## Available NLP Models")
|
| 228 |
model_index = gr.Slider(label="Model Index", minimum=0, maximum=len(self.nlp_model_names)-1, step=1)
|
|
@@ -233,6 +221,19 @@ class App:
|
|
| 233 |
inputs=[input_text, model_index],
|
| 234 |
outputs="text"
|
| 235 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
return demo
|
| 238 |
|
|
@@ -275,56 +276,6 @@ class App:
|
|
| 275 |
if system_message:
|
| 276 |
print(system_message)
|
| 277 |
|
| 278 |
-
def launch_app(self):
|
| 279 |
-
demo = self.build_app()
|
| 280 |
-
demo.launch()
|
| 281 |
-
|
| 282 |
-
def main():
|
| 283 |
-
try:
|
| 284 |
-
app = App()
|
| 285 |
-
demo = app.build_app()
|
| 286 |
-
demo.launch()
|
| 287 |
-
except Exception as e:
|
| 288 |
-
print(f"Error launching app: {e}")
|
| 289 |
-
|
| 290 |
-
if __name__ == "__main__":
|
| 291 |
-
main()
|
| 292 |
-
|
| 293 |
-
def run(self):
|
| 294 |
-
self._print_welcome_message()
|
| 295 |
-
|
| 296 |
-
while True:
|
| 297 |
-
try:
|
| 298 |
-
input_text = self._get_user_input()
|
| 299 |
-
if input_text.lower() == 'exit':
|
| 300 |
-
break
|
| 301 |
-
elif input_text.lower() == 'launch':
|
| 302 |
-
self.launch_app()
|
| 303 |
-
continue
|
| 304 |
-
|
| 305 |
-
output, system_message = self.process_input(input_text)
|
| 306 |
-
self._display_output(output, system_message)
|
| 307 |
-
|
| 308 |
-
except EOFError:
|
| 309 |
-
print("Error: Input reading interrupted. Please provide valid input.")
|
| 310 |
-
except KeyboardInterrupt:
|
| 311 |
-
print("\nApplication stopped by user.")
|
| 312 |
-
break
|
| 313 |
-
except Exception as e:
|
| 314 |
-
print(f"An error occurred: {str(e)}")
|
| 315 |
-
|
| 316 |
-
print("Thank you for using the Python App Builder. Goodbye!")
|
| 317 |
-
|
| 318 |
-
def _get_user_input(self):
|
| 319 |
-
try:
|
| 320 |
-
return input("Enter input: ").strip()
|
| 321 |
-
except EOFError:
|
| 322 |
-
print("Error: Input stream closed unexpectedly.")
|
| 323 |
-
return ""
|
| 324 |
-
except Exception as e:
|
| 325 |
-
print(f"Error reading input: {str(e)}")
|
| 326 |
-
return ""
|
| 327 |
-
|
| 328 |
def launch_app(self):
|
| 329 |
print("Launching app...")
|
| 330 |
demo = self.build_app()
|
|
|
|
| 199 |
|
| 200 |
def build_app(self):
|
| 201 |
with gr.Blocks() as demo:
|
| 202 |
+
with gr.Tab("App Canvas"):
|
| 203 |
+
app_canvas = gr.HTML(self.update_app_canvas())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
with gr.Tab("Terminal"):
|
| 205 |
gr.Markdown("## Terminal")
|
| 206 |
terminal_input = gr.Textbox(label="Input")
|
|
|
|
| 211 |
inputs=[terminal_input],
|
| 212 |
outputs=[terminal_output]
|
| 213 |
)
|
|
|
|
| 214 |
with gr.Tab("NLP Models"):
|
| 215 |
gr.Markdown("## Available NLP Models")
|
| 216 |
model_index = gr.Slider(label="Model Index", minimum=0, maximum=len(self.nlp_model_names)-1, step=1)
|
|
|
|
| 221 |
inputs=[input_text, model_index],
|
| 222 |
outputs="text"
|
| 223 |
)
|
| 224 |
+
# Add components to the app canvas dynamically
|
| 225 |
+
for component in self.app_state["components"]:
|
| 226 |
+
component_type = component["type"]
|
| 227 |
+
properties = component["properties"]
|
| 228 |
+
|
| 229 |
+
if component_type == "Button":
|
| 230 |
+
gr.Button(value=properties["label"], variant="primary")
|
| 231 |
+
elif component_type == "Text Input":
|
| 232 |
+
gr.Textbox(label=properties["placeholder"])
|
| 233 |
+
elif component_type == "Image":
|
| 234 |
+
gr.Image(label=properties["alt"])
|
| 235 |
+
elif component_type == "Dropdown":
|
| 236 |
+
gr.Dropdown(choices=properties["choices"], label="Dropdown")
|
| 237 |
|
| 238 |
return demo
|
| 239 |
|
|
|
|
| 276 |
if system_message:
|
| 277 |
print(system_message)
|
| 278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
def launch_app(self):
|
| 280 |
print("Launching app...")
|
| 281 |
demo = self.build_app()
|