Spaces:
Runtime error
Runtime error
nananie143 commited on
Commit ·
6abb09c
1
Parent(s): 4128a97
Enhanced Gradio UI with better error handling, logs tab, and sharing enabled
Browse files
app.py
CHANGED
|
@@ -982,64 +982,102 @@ def app_generator(requirements: str):
|
|
| 982 |
loop.close()
|
| 983 |
|
| 984 |
# Gradio UI
|
| 985 |
-
with gr.Blocks() as ui:
|
| 986 |
-
gr.Markdown("# Autonomous App Generator with
|
| 987 |
gr.Markdown("""
|
| 988 |
## Instructions
|
| 989 |
1. Describe the app you want to build in detail
|
| 990 |
2. Include any specific requirements or features
|
| 991 |
3. Click 'Generate App' to start the process
|
| 992 |
4. Download your generated app from the provided link
|
| 993 |
-
""")
|
| 994 |
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
|
|
|
|
|
|
|
|
|
| 1002 |
|
| 1003 |
with gr.Row():
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1012 |
|
| 1013 |
def process_output(requirements):
|
| 1014 |
try:
|
|
|
|
|
|
|
|
|
|
| 1015 |
# Generate the app
|
| 1016 |
-
result = app_generator(requirements)
|
| 1017 |
|
| 1018 |
# Extract download path from the result
|
| 1019 |
download_path = None
|
|
|
|
|
|
|
| 1020 |
for line in result.split('\n'):
|
| 1021 |
if line.startswith("To download your project, use this path:"):
|
| 1022 |
download_path = line.split(": ")[1].strip()
|
| 1023 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1024 |
|
| 1025 |
if download_path and Path(download_path).exists():
|
| 1026 |
-
return result, download_path
|
| 1027 |
else:
|
| 1028 |
-
|
|
|
|
|
|
|
|
|
|
| 1029 |
except Exception as e:
|
| 1030 |
error_msg = f"Failed to generate app: {str(e)}"
|
| 1031 |
logger.error(error_msg)
|
| 1032 |
-
|
|
|
|
| 1033 |
|
| 1034 |
generate_button.click(
|
| 1035 |
process_output,
|
| 1036 |
inputs=[requirements_input],
|
| 1037 |
-
outputs=[output, file_output]
|
| 1038 |
)
|
| 1039 |
|
| 1040 |
# Run the Gradio app
|
| 1041 |
if __name__ == "__main__":
|
| 1042 |
try:
|
| 1043 |
-
ui.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1044 |
except Exception as e:
|
| 1045 |
logger.error(f"Failed to launch Gradio interface: {str(e)}")
|
|
|
|
| 982 |
loop.close()
|
| 983 |
|
| 984 |
# Gradio UI
|
| 985 |
+
with gr.Blocks(theme=gr.themes.Soft()) as ui:
|
| 986 |
+
gr.Markdown("# Autonomous App Generator with AI Flow")
|
| 987 |
gr.Markdown("""
|
| 988 |
## Instructions
|
| 989 |
1. Describe the app you want to build in detail
|
| 990 |
2. Include any specific requirements or features
|
| 991 |
3. Click 'Generate App' to start the process
|
| 992 |
4. Download your generated app from the provided link
|
|
|
|
| 993 |
|
| 994 |
+
### Example:
|
| 995 |
+
```
|
| 996 |
+
Create a personal task management application with:
|
| 997 |
+
- User authentication (email/password, Google OAuth)
|
| 998 |
+
- Task management (CRUD, priorities, due dates, reminders)
|
| 999 |
+
- Modern UI with dark/light theme
|
| 1000 |
+
- Real-time updates using WebSocket
|
| 1001 |
+
- PostgreSQL and Redis for storage
|
| 1002 |
+
```
|
| 1003 |
+
""")
|
| 1004 |
|
| 1005 |
with gr.Row():
|
| 1006 |
+
with gr.Column(scale=4):
|
| 1007 |
+
requirements_input = gr.Textbox(
|
| 1008 |
+
label="App Requirements",
|
| 1009 |
+
placeholder="Describe the app you want to build...",
|
| 1010 |
+
lines=10
|
| 1011 |
+
)
|
| 1012 |
+
generate_button = gr.Button("Generate App", variant="primary")
|
| 1013 |
+
|
| 1014 |
+
with gr.Column(scale=6):
|
| 1015 |
+
with gr.Tabs():
|
| 1016 |
+
with gr.TabItem("Output"):
|
| 1017 |
+
output = gr.Markdown(
|
| 1018 |
+
label="Generated App Details",
|
| 1019 |
+
value="Your app details will appear here..."
|
| 1020 |
+
)
|
| 1021 |
+
with gr.TabItem("Download"):
|
| 1022 |
+
file_output = gr.File(
|
| 1023 |
+
label="Download Generated App",
|
| 1024 |
+
interactive=False
|
| 1025 |
+
)
|
| 1026 |
+
with gr.TabItem("Logs"):
|
| 1027 |
+
log_output = gr.Markdown(
|
| 1028 |
+
label="Generation Logs",
|
| 1029 |
+
value="Logs will appear here..."
|
| 1030 |
+
)
|
| 1031 |
|
| 1032 |
def process_output(requirements):
|
| 1033 |
try:
|
| 1034 |
+
# Initialize log output
|
| 1035 |
+
log_output.value = "Starting app generation...\n"
|
| 1036 |
+
|
| 1037 |
# Generate the app
|
| 1038 |
+
result = asyncio.run(app_generator(requirements))
|
| 1039 |
|
| 1040 |
# Extract download path from the result
|
| 1041 |
download_path = None
|
| 1042 |
+
logs = []
|
| 1043 |
+
|
| 1044 |
for line in result.split('\n'):
|
| 1045 |
if line.startswith("To download your project, use this path:"):
|
| 1046 |
download_path = line.split(": ")[1].strip()
|
| 1047 |
+
if line.startswith("2025-") or line.startswith("INFO") or line.startswith("ERROR"):
|
| 1048 |
+
logs.append(line)
|
| 1049 |
+
|
| 1050 |
+
# Update logs
|
| 1051 |
+
log_output.value = "\n".join(logs)
|
| 1052 |
|
| 1053 |
if download_path and Path(download_path).exists():
|
| 1054 |
+
return result, download_path, "\n".join(logs)
|
| 1055 |
else:
|
| 1056 |
+
error_msg = "Failed to generate download file"
|
| 1057 |
+
log_output.value += f"\nERROR: {error_msg}"
|
| 1058 |
+
return result, None, "\n".join(logs)
|
| 1059 |
+
|
| 1060 |
except Exception as e:
|
| 1061 |
error_msg = f"Failed to generate app: {str(e)}"
|
| 1062 |
logger.error(error_msg)
|
| 1063 |
+
log_output.value += f"\nERROR: {error_msg}"
|
| 1064 |
+
return error_msg, None, log_output.value
|
| 1065 |
|
| 1066 |
generate_button.click(
|
| 1067 |
process_output,
|
| 1068 |
inputs=[requirements_input],
|
| 1069 |
+
outputs=[output, file_output, log_output]
|
| 1070 |
)
|
| 1071 |
|
| 1072 |
# Run the Gradio app
|
| 1073 |
if __name__ == "__main__":
|
| 1074 |
try:
|
| 1075 |
+
ui.launch(
|
| 1076 |
+
share=True, # Enable sharing
|
| 1077 |
+
server_name="0.0.0.0",
|
| 1078 |
+
server_port=7860,
|
| 1079 |
+
show_error=True,
|
| 1080 |
+
enable_queue=True
|
| 1081 |
+
)
|
| 1082 |
except Exception as e:
|
| 1083 |
logger.error(f"Failed to launch Gradio interface: {str(e)}")
|