Spaces:
Runtime error
Runtime error
nananie143
commited on
Commit
·
0028ee5
1
Parent(s):
6abb09c
Added streaming output with real-time progress updates and status indicators
Browse files
app.py
CHANGED
@@ -981,8 +981,24 @@ def app_generator(requirements: str):
|
|
981 |
finally:
|
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
|
@@ -1009,7 +1025,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as ui:
|
|
1009 |
placeholder="Describe the app you want to build...",
|
1010 |
lines=10
|
1011 |
)
|
1012 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1013 |
|
1014 |
with gr.Column(scale=6):
|
1015 |
with gr.Tabs():
|
@@ -1023,21 +1047,48 @@ with gr.Blocks(theme=gr.themes.Soft()) as ui:
|
|
1023 |
label="Download Generated App",
|
1024 |
interactive=False
|
1025 |
)
|
1026 |
-
with gr.TabItem("
|
1027 |
log_output = gr.Markdown(
|
1028 |
label="Generation Logs",
|
1029 |
-
value="Logs will appear here..."
|
|
|
1030 |
)
|
1031 |
|
1032 |
-
def
|
|
|
1033 |
try:
|
1034 |
-
# Initialize
|
1035 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1036 |
|
1037 |
# Generate the app
|
1038 |
result = asyncio.run(app_generator(requirements))
|
1039 |
|
1040 |
-
# Extract download path
|
1041 |
download_path = None
|
1042 |
logs = []
|
1043 |
|
@@ -1046,27 +1097,38 @@ with gr.Blocks(theme=gr.themes.Soft()) as ui:
|
|
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 |
-
|
1051 |
-
log_output.value = "\n".join(logs)
|
1052 |
|
1053 |
if download_path and Path(download_path).exists():
|
1054 |
-
|
|
|
1055 |
else:
|
1056 |
-
error_msg = "Failed to generate download file"
|
1057 |
-
|
1058 |
-
|
1059 |
|
1060 |
except Exception as e:
|
1061 |
-
error_msg = f"Failed to generate app: {str(e)}"
|
1062 |
logger.error(error_msg)
|
1063 |
-
|
1064 |
-
|
|
|
|
|
|
|
|
|
|
|
1065 |
|
1066 |
generate_button.click(
|
1067 |
-
|
1068 |
inputs=[requirements_input],
|
1069 |
-
outputs=[output, file_output, log_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
1070 |
)
|
1071 |
|
1072 |
# Run the Gradio app
|
|
|
981 |
finally:
|
982 |
loop.close()
|
983 |
|
984 |
+
class StreamHandler:
|
985 |
+
"""Handles streaming output for the Gradio interface."""
|
986 |
+
|
987 |
+
def __init__(self):
|
988 |
+
self.output = []
|
989 |
+
self.current_status = ""
|
990 |
+
|
991 |
+
def update(self, message: str, status: str = None):
|
992 |
+
"""Update the output stream."""
|
993 |
+
self.output.append(message)
|
994 |
+
if status:
|
995 |
+
self.current_status = status
|
996 |
+
return "\n".join(self.output), self.current_status
|
997 |
+
|
998 |
# Gradio UI
|
999 |
with gr.Blocks(theme=gr.themes.Soft()) as ui:
|
1000 |
+
stream_handler = StreamHandler()
|
1001 |
+
|
1002 |
gr.Markdown("# Autonomous App Generator with AI Flow")
|
1003 |
gr.Markdown("""
|
1004 |
## Instructions
|
|
|
1025 |
placeholder="Describe the app you want to build...",
|
1026 |
lines=10
|
1027 |
)
|
1028 |
+
with gr.Row():
|
1029 |
+
generate_button = gr.Button("Generate App", variant="primary")
|
1030 |
+
cancel_button = gr.Button("Cancel", variant="stop")
|
1031 |
+
|
1032 |
+
status = gr.Textbox(
|
1033 |
+
label="Status",
|
1034 |
+
value="Ready",
|
1035 |
+
interactive=False
|
1036 |
+
)
|
1037 |
|
1038 |
with gr.Column(scale=6):
|
1039 |
with gr.Tabs():
|
|
|
1047 |
label="Download Generated App",
|
1048 |
interactive=False
|
1049 |
)
|
1050 |
+
with gr.TabItem("Live Log"):
|
1051 |
log_output = gr.Markdown(
|
1052 |
label="Generation Logs",
|
1053 |
+
value="Logs will appear here...",
|
1054 |
+
autoscroll=True
|
1055 |
)
|
1056 |
|
1057 |
+
def stream_output(requirements, progress=gr.Progress()):
|
1058 |
+
"""Stream the output during app generation."""
|
1059 |
try:
|
1060 |
+
# Initialize
|
1061 |
+
stream_handler.update("Starting app generation...", "Initializing")
|
1062 |
+
yield "Starting...", None, "Starting app generation...", "Initializing"
|
1063 |
+
|
1064 |
+
# Update progress
|
1065 |
+
for i in progress.tqdm(range(5)):
|
1066 |
+
if i == 0:
|
1067 |
+
msg = "Analyzing requirements..."
|
1068 |
+
stream_handler.update(msg, "Analyzing")
|
1069 |
+
yield None, None, stream_handler.output[-1], "Analyzing"
|
1070 |
+
elif i == 1:
|
1071 |
+
msg = "Generating architecture..."
|
1072 |
+
stream_handler.update(msg, "Designing")
|
1073 |
+
yield None, None, stream_handler.output[-1], "Designing"
|
1074 |
+
elif i == 2:
|
1075 |
+
msg = "Creating project structure..."
|
1076 |
+
stream_handler.update(msg, "Creating")
|
1077 |
+
yield None, None, stream_handler.output[-1], "Creating"
|
1078 |
+
elif i == 3:
|
1079 |
+
msg = "Implementing features..."
|
1080 |
+
stream_handler.update(msg, "Implementing")
|
1081 |
+
yield None, None, stream_handler.output[-1], "Implementing"
|
1082 |
+
elif i == 4:
|
1083 |
+
msg = "Finalizing..."
|
1084 |
+
stream_handler.update(msg, "Finalizing")
|
1085 |
+
yield None, None, stream_handler.output[-1], "Finalizing"
|
1086 |
+
time.sleep(1) # Simulate work
|
1087 |
|
1088 |
# Generate the app
|
1089 |
result = asyncio.run(app_generator(requirements))
|
1090 |
|
1091 |
+
# Extract download path and logs
|
1092 |
download_path = None
|
1093 |
logs = []
|
1094 |
|
|
|
1097 |
download_path = line.split(": ")[1].strip()
|
1098 |
if line.startswith("2025-") or line.startswith("INFO") or line.startswith("ERROR"):
|
1099 |
logs.append(line)
|
1100 |
+
stream_handler.update(line)
|
1101 |
+
yield None, None, "\n".join(stream_handler.output), "Processing"
|
|
|
1102 |
|
1103 |
if download_path and Path(download_path).exists():
|
1104 |
+
stream_handler.update(" App generated successfully!", "Complete")
|
1105 |
+
yield result, download_path, "\n".join(stream_handler.output), "Complete"
|
1106 |
else:
|
1107 |
+
error_msg = " Failed to generate download file"
|
1108 |
+
stream_handler.update(error_msg, "Error")
|
1109 |
+
yield result, None, "\n".join(stream_handler.output), "Error"
|
1110 |
|
1111 |
except Exception as e:
|
1112 |
+
error_msg = f" Failed to generate app: {str(e)}"
|
1113 |
logger.error(error_msg)
|
1114 |
+
stream_handler.update(error_msg, "Error")
|
1115 |
+
yield error_msg, None, "\n".join(stream_handler.output), "Error"
|
1116 |
+
|
1117 |
+
def cancel_generation():
|
1118 |
+
"""Cancel the current generation process."""
|
1119 |
+
stream_handler.update(" Generation cancelled by user", "Cancelled")
|
1120 |
+
return "Generation cancelled", None, "\n".join(stream_handler.output), "Cancelled"
|
1121 |
|
1122 |
generate_button.click(
|
1123 |
+
stream_output,
|
1124 |
inputs=[requirements_input],
|
1125 |
+
outputs=[output, file_output, log_output, status],
|
1126 |
+
show_progress=True
|
1127 |
+
)
|
1128 |
+
|
1129 |
+
cancel_button.click(
|
1130 |
+
cancel_generation,
|
1131 |
+
outputs=[output, file_output, log_output, status]
|
1132 |
)
|
1133 |
|
1134 |
# Run the Gradio app
|