Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -265,5 +265,74 @@ def main():
|
|
| 265 |
except Exception as e:
|
| 266 |
print(f"Failed to initialize the application: {str(e)}")
|
| 267 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
if __name__ == "__main__":
|
| 269 |
main()
|
|
|
|
| 265 |
except Exception as e:
|
| 266 |
print(f"Failed to initialize the application: {str(e)}")
|
| 267 |
|
| 268 |
+
def build_app(self):
|
| 269 |
+
with gr.Blocks() as demo:
|
| 270 |
+
for component in self.app_state["components"]:
|
| 271 |
+
component_type = component["type"]
|
| 272 |
+
properties = component["properties"]
|
| 273 |
+
|
| 274 |
+
if component_type == "Button":
|
| 275 |
+
gr.Button(value=properties["label"], variant="primary")
|
| 276 |
+
elif component_type == "Text Input":
|
| 277 |
+
gr.Textbox(label=properties["placeholder"])
|
| 278 |
+
elif component_type == "Image":
|
| 279 |
+
gr.Image(label=properties["alt"])
|
| 280 |
+
elif component_type == "Dropdown":
|
| 281 |
+
gr.Dropdown(choices=properties["choices"], label="Dropdown")
|
| 282 |
+
|
| 283 |
+
return demo
|
| 284 |
+
|
| 285 |
+
def launch_app(self):
|
| 286 |
+
demo = self.build_app()
|
| 287 |
+
demo.launch()
|
| 288 |
+
|
| 289 |
+
def run(self):
|
| 290 |
+
self._print_welcome_message()
|
| 291 |
+
|
| 292 |
+
while True:
|
| 293 |
+
try:
|
| 294 |
+
input_text = self._get_user_input()
|
| 295 |
+
if input_text.lower() == 'exit':
|
| 296 |
+
break
|
| 297 |
+
elif input_text.lower() == 'launch':
|
| 298 |
+
self.launch_app()
|
| 299 |
+
continue
|
| 300 |
+
|
| 301 |
+
output, system_message = self.process_input(input_text)
|
| 302 |
+
self._display_output(output, system_message)
|
| 303 |
+
|
| 304 |
+
except EOFError:
|
| 305 |
+
print("Error: Input reading interrupted. Please provide valid input.")
|
| 306 |
+
except KeyboardInterrupt:
|
| 307 |
+
print("\nApplication stopped by user.")
|
| 308 |
+
break
|
| 309 |
+
except Exception as e:
|
| 310 |
+
print(f"An error occurred: {str(e)}")
|
| 311 |
+
|
| 312 |
+
def _print_welcome_message(self):
|
| 313 |
+
print("Welcome to the Python App Builder!")
|
| 314 |
+
print("Type 'help' to see the available commands.")
|
| 315 |
+
print("Type 'launch' to build and launch the Gradio app.")
|
| 316 |
+
print("Type 'exit' to quit the application.")
|
| 317 |
+
print("-" * 50)
|
| 318 |
+
|
| 319 |
+
def _get_user_input(self):
|
| 320 |
+
return input("Enter input: ").strip()
|
| 321 |
+
|
| 322 |
+
def _display_output(self, output, system_message):
|
| 323 |
+
if output:
|
| 324 |
+
print(output)
|
| 325 |
+
if system_message:
|
| 326 |
+
print(system_message)
|
| 327 |
+
|
| 328 |
+
# The main function remains outside the class
|
| 329 |
+
def main():
|
| 330 |
+
try:
|
| 331 |
+
app = App()
|
| 332 |
+
print(f"===== Application Startup at {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} =====")
|
| 333 |
+
app.run()
|
| 334 |
+
except Exception as e:
|
| 335 |
+
print(f"Failed to initialize the application: {str(e)}")
|
| 336 |
+
|
| 337 |
if __name__ == "__main__":
|
| 338 |
main()
|