Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -222,71 +222,7 @@ 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 |
-
|
| 228 |
-
while True:
|
| 229 |
-
try:
|
| 230 |
-
input_text = self._get_user_input()
|
| 231 |
-
if input_text.lower() == 'exit':
|
| 232 |
-
break
|
| 233 |
-
|
| 234 |
-
output, system_message = self.process_input(input_text)
|
| 235 |
-
self._display_output(output, system_message)
|
| 236 |
-
|
| 237 |
-
except EOFError:
|
| 238 |
-
print("Error: Input reading interrupted. Please provide valid input.")
|
| 239 |
-
except KeyboardInterrupt:
|
| 240 |
-
print("\nApplication stopped by user.")
|
| 241 |
-
break
|
| 242 |
-
except Exception as e:
|
| 243 |
-
print(f"An error occurred: {str(e)}")
|
| 244 |
-
|
| 245 |
-
def _print_welcome_message(self):
|
| 246 |
-
print("Welcome to the Python App Builder!")
|
| 247 |
-
print("Type 'help' to see the available commands.")
|
| 248 |
-
print("Type 'exit' to quit the application.")
|
| 249 |
-
print("-" * 50)
|
| 250 |
-
|
| 251 |
-
def _get_user_input(self):
|
| 252 |
-
return input("Enter input: ").strip()
|
| 253 |
-
|
| 254 |
-
def _display_output(self, output, system_message):
|
| 255 |
-
if output:
|
| 256 |
-
print(output)
|
| 257 |
-
if system_message:
|
| 258 |
-
print(system_message)
|
| 259 |
-
|
| 260 |
-
def main():
|
| 261 |
-
try:
|
| 262 |
-
app = App()
|
| 263 |
-
print(f"===== Application Startup at {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} =====")
|
| 264 |
-
app.run()
|
| 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:
|
|
@@ -309,15 +245,14 @@ def run(self):
|
|
| 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 |
-
|
| 320 |
-
def _get_user_input(self):
|
| 321 |
return input("Enter input: ").strip()
|
| 322 |
|
| 323 |
def _display_output(self, output, system_message):
|
|
@@ -325,14 +260,31 @@ def _get_user_input(self):
|
|
| 325 |
print(output)
|
| 326 |
if system_message:
|
| 327 |
print(system_message)
|
| 328 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
def main():
|
| 330 |
-
|
| 331 |
-
|
| 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()
|
|
|
|
| 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 |
|
| 228 |
while True:
|
|
|
|
| 245 |
except Exception as e:
|
| 246 |
print(f"An error occurred: {str(e)}")
|
| 247 |
|
| 248 |
+
def _print_welcome_message(self):
|
| 249 |
print("Welcome to the Python App Builder!")
|
| 250 |
print("Type 'help' to see the available commands.")
|
| 251 |
print("Type 'launch' to build and launch the Gradio app.")
|
| 252 |
print("Type 'exit' to quit the application.")
|
| 253 |
print("-" * 50)
|
| 254 |
|
| 255 |
+
def _get_user_input(self):
|
|
|
|
| 256 |
return input("Enter input: ").strip()
|
| 257 |
|
| 258 |
def _display_output(self, output, system_message):
|
|
|
|
| 260 |
print(output)
|
| 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 |
+
app = App()
|
| 287 |
+
app.run()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
|
| 289 |
if __name__ == "__main__":
|
| 290 |
main()
|