Spaces:
Runtime error
Runtime error
nananie143
commited on
Commit
·
8172412
1
Parent(s):
0028ee5
Fixed log output and improved message formatting with timestamps and emojis
Browse files
app.py
CHANGED
@@ -990,9 +990,14 @@ class StreamHandler:
|
|
990 |
|
991 |
def update(self, message: str, status: str = None):
|
992 |
"""Update the output stream."""
|
993 |
-
|
|
|
|
|
994 |
if status:
|
995 |
self.current_status = status
|
|
|
|
|
|
|
996 |
return "\n".join(self.output), self.current_status
|
997 |
|
998 |
# Gradio UI
|
@@ -1048,44 +1053,48 @@ with gr.Blocks(theme=gr.themes.Soft()) as ui:
|
|
1048 |
interactive=False
|
1049 |
)
|
1050 |
with gr.TabItem("Live Log"):
|
1051 |
-
log_output = gr.
|
1052 |
label="Generation Logs",
|
1053 |
value="Logs will appear here...",
|
1054 |
-
|
|
|
|
|
|
|
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
|
@@ -1095,13 +1104,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as ui:
|
|
1095 |
for line in result.split('\n'):
|
1096 |
if line.startswith("To download your project, use this path:"):
|
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"
|
@@ -1109,7 +1119,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as ui:
|
|
1109 |
yield result, None, "\n".join(stream_handler.output), "Error"
|
1110 |
|
1111 |
except Exception as e:
|
1112 |
-
error_msg = f"
|
1113 |
logger.error(error_msg)
|
1114 |
stream_handler.update(error_msg, "Error")
|
1115 |
yield error_msg, None, "\n".join(stream_handler.output), "Error"
|
|
|
990 |
|
991 |
def update(self, message: str, status: str = None):
|
992 |
"""Update the output stream."""
|
993 |
+
timestamp = datetime.now().strftime("%H:%M:%S")
|
994 |
+
formatted_message = f"[{timestamp}] {message}"
|
995 |
+
self.output.append(formatted_message)
|
996 |
if status:
|
997 |
self.current_status = status
|
998 |
+
# Keep only the last 100 lines
|
999 |
+
if len(self.output) > 100:
|
1000 |
+
self.output = self.output[-100:]
|
1001 |
return "\n".join(self.output), self.current_status
|
1002 |
|
1003 |
# Gradio UI
|
|
|
1053 |
interactive=False
|
1054 |
)
|
1055 |
with gr.TabItem("Live Log"):
|
1056 |
+
log_output = gr.Textbox(
|
1057 |
label="Generation Logs",
|
1058 |
value="Logs will appear here...",
|
1059 |
+
lines=10,
|
1060 |
+
max_lines=20,
|
1061 |
+
interactive=False,
|
1062 |
+
show_copy_button=True
|
1063 |
)
|
1064 |
|
1065 |
def stream_output(requirements, progress=gr.Progress()):
|
1066 |
"""Stream the output during app generation."""
|
1067 |
try:
|
1068 |
# Initialize
|
1069 |
+
stream_handler.update(" Starting app generation...", "Initializing")
|
1070 |
+
yield "Starting...", None, " Starting app generation...", "Initializing"
|
1071 |
|
1072 |
# Update progress
|
1073 |
for i in progress.tqdm(range(5)):
|
1074 |
if i == 0:
|
1075 |
+
msg = " Analyzing requirements..."
|
1076 |
stream_handler.update(msg, "Analyzing")
|
1077 |
yield None, None, stream_handler.output[-1], "Analyzing"
|
1078 |
elif i == 1:
|
1079 |
+
msg = " Generating architecture..."
|
1080 |
stream_handler.update(msg, "Designing")
|
1081 |
yield None, None, stream_handler.output[-1], "Designing"
|
1082 |
elif i == 2:
|
1083 |
+
msg = " Creating project structure..."
|
1084 |
stream_handler.update(msg, "Creating")
|
1085 |
yield None, None, stream_handler.output[-1], "Creating"
|
1086 |
elif i == 3:
|
1087 |
+
msg = " Implementing features..."
|
1088 |
stream_handler.update(msg, "Implementing")
|
1089 |
yield None, None, stream_handler.output[-1], "Implementing"
|
1090 |
elif i == 4:
|
1091 |
+
msg = " Finalizing..."
|
1092 |
stream_handler.update(msg, "Finalizing")
|
1093 |
yield None, None, stream_handler.output[-1], "Finalizing"
|
1094 |
time.sleep(1) # Simulate work
|
1095 |
|
1096 |
# Generate the app
|
1097 |
+
stream_handler.update(" Running AI Flow system...", "Processing")
|
1098 |
result = asyncio.run(app_generator(requirements))
|
1099 |
|
1100 |
# Extract download path and logs
|
|
|
1104 |
for line in result.split('\n'):
|
1105 |
if line.startswith("To download your project, use this path:"):
|
1106 |
download_path = line.split(": ")[1].strip()
|
1107 |
+
stream_handler.update(f" Generated download file: {Path(download_path).name}", "Processing")
|
1108 |
if line.startswith("2025-") or line.startswith("INFO") or line.startswith("ERROR"):
|
1109 |
logs.append(line)
|
1110 |
+
stream_handler.update(line.split(" - ")[-1], "Processing")
|
1111 |
yield None, None, "\n".join(stream_handler.output), "Processing"
|
1112 |
|
1113 |
if download_path and Path(download_path).exists():
|
1114 |
+
stream_handler.update(" App generated successfully! Download is ready.", "Complete")
|
1115 |
yield result, download_path, "\n".join(stream_handler.output), "Complete"
|
1116 |
else:
|
1117 |
error_msg = " Failed to generate download file"
|
|
|
1119 |
yield result, None, "\n".join(stream_handler.output), "Error"
|
1120 |
|
1121 |
except Exception as e:
|
1122 |
+
error_msg = f" Error: {str(e)}"
|
1123 |
logger.error(error_msg)
|
1124 |
stream_handler.update(error_msg, "Error")
|
1125 |
yield error_msg, None, "\n".join(stream_handler.output), "Error"
|