Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import time
|
| 3 |
import os
|
| 4 |
from backend import (
|
| 5 |
-
init_db,
|
| 6 |
create_user,
|
| 7 |
get_user_by_username,
|
| 8 |
verify_password,
|
|
@@ -89,7 +89,7 @@ def login_and_setup(username, password, user_state):
|
|
| 89 |
gr.update(value=welcome_message),
|
| 90 |
gr.update(value=format_projects_list(projects)),
|
| 91 |
gr.update(choices=get_project_choices(user_id), value=None),
|
| 92 |
-
gr.update(value=format_files_list(projects))
|
| 93 |
)
|
| 94 |
return user_state, gr.update(), gr.update()
|
| 95 |
|
|
@@ -113,7 +113,7 @@ def start_project_flow(prompt, user_state):
|
|
| 113 |
gr.update(value=format_projects_list(projects)),
|
| 114 |
gr.update(choices=get_project_choices(user_id), value=project_id),
|
| 115 |
gr.Tabs(selected="logs_tab"),
|
| 116 |
-
gr.update(value=format_files_list(projects))
|
| 117 |
)
|
| 118 |
|
| 119 |
def refresh_all_projects(user_state):
|
|
@@ -129,6 +129,13 @@ def refresh_all_projects(user_state):
|
|
| 129 |
gr.update(value=format_files_list(projects))
|
| 130 |
)
|
| 131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
# --- CUSTOM GENERATOR LOOPS FOR LIVE UPDATES ---
|
| 133 |
|
| 134 |
def system_stats_loop():
|
|
@@ -143,7 +150,6 @@ def stream_logs(project_id):
|
|
| 143 |
yield "⬅️ Select a project from the dropdown to see its live logs.", gr.update(visible=False)
|
| 144 |
return
|
| 145 |
|
| 146 |
-
# On first run for a new selection, ensure the download button is hidden
|
| 147 |
yield "Fetching logs...", gr.update(visible=False)
|
| 148 |
|
| 149 |
while True:
|
|
@@ -151,7 +157,6 @@ def stream_logs(project_id):
|
|
| 151 |
if project:
|
| 152 |
logs = project['logs'] if project['logs'] else f"🕒 Project #{project_id} is queued or starting... Logs will appear here shortly."
|
| 153 |
|
| 154 |
-
# Check for terminal states
|
| 155 |
if project['status'] == 'completed':
|
| 156 |
final_log = logs + "\n\n✅ **Project Completed!** Your file is ready for download."
|
| 157 |
zip_path = project['zip_path']
|
|
@@ -159,15 +164,13 @@ def stream_logs(project_id):
|
|
| 159 |
yield final_log, gr.update(value=zip_path, visible=True)
|
| 160 |
else:
|
| 161 |
yield logs + "\n\n⚠️ **Warning:** Project completed, but the ZIP file was not found.", gr.update(visible=False)
|
| 162 |
-
break
|
| 163 |
|
| 164 |
elif project['status'] == 'failed':
|
| 165 |
yield logs, gr.update(visible=False)
|
| 166 |
-
break
|
| 167 |
|
| 168 |
-
# Otherwise, just stream the current logs
|
| 169 |
yield logs, gr.update(visible=False)
|
| 170 |
-
|
| 171 |
else:
|
| 172 |
yield f"Error: Project #{project_id} not found.", gr.update(visible=False)
|
| 173 |
break
|
|
@@ -210,10 +213,8 @@ with gr.Blocks(title="Code Agents Pro", theme=gr.themes.Soft()) as demo:
|
|
| 210 |
with gr.Group(elem_classes=["logs-container"]):
|
| 211 |
logs_display = gr.Markdown("Logs will appear here in real-time.", elem_classes=["monospace"])
|
| 212 |
|
| 213 |
-
# File download component, initially hidden
|
| 214 |
download_zip_ui = gr.File(label="Download Project ZIP", visible=False, interactive=False)
|
| 215 |
|
| 216 |
-
# NEW FILES TAB
|
| 217 |
with gr.Tab("📁 Files", id="files_tab"):
|
| 218 |
gr.Markdown("### 📦 Download Completed Projects")
|
| 219 |
refresh_files_btn = gr.Button("🔄 Refresh Files")
|
|
@@ -233,7 +234,7 @@ with gr.Blocks(title="Code Agents Pro", theme=gr.themes.Soft()) as demo:
|
|
| 233 |
welcome_msg,
|
| 234 |
projects_display,
|
| 235 |
project_selector,
|
| 236 |
-
files_display
|
| 237 |
]
|
| 238 |
)
|
| 239 |
|
|
@@ -246,7 +247,7 @@ with gr.Blocks(title="Code Agents Pro", theme=gr.themes.Soft()) as demo:
|
|
| 246 |
projects_display,
|
| 247 |
project_selector,
|
| 248 |
tabs,
|
| 249 |
-
files_display
|
| 250 |
]
|
| 251 |
)
|
| 252 |
|
|
@@ -256,13 +257,12 @@ with gr.Blocks(title="Code Agents Pro", theme=gr.themes.Soft()) as demo:
|
|
| 256 |
outputs=[
|
| 257 |
projects_display,
|
| 258 |
project_selector,
|
| 259 |
-
files_display
|
| 260 |
]
|
| 261 |
)
|
| 262 |
|
| 263 |
-
# NEW: Refresh files tab button
|
| 264 |
refresh_files_btn.click(
|
| 265 |
-
fn=
|
| 266 |
inputs=[user_state],
|
| 267 |
outputs=[files_display]
|
| 268 |
)
|
|
@@ -278,7 +278,6 @@ with gr.Blocks(title="Code Agents Pro", theme=gr.themes.Soft()) as demo:
|
|
| 278 |
outputs=ram_monitor
|
| 279 |
)
|
| 280 |
|
| 281 |
-
# Initialize the database when the app loads
|
| 282 |
demo.load(init_db, inputs=None, outputs=None, show_progress=False)
|
| 283 |
|
| 284 |
gr.HTML("""
|
|
|
|
| 2 |
import time
|
| 3 |
import os
|
| 4 |
from backend import (
|
| 5 |
+
init_db,
|
| 6 |
create_user,
|
| 7 |
get_user_by_username,
|
| 8 |
verify_password,
|
|
|
|
| 89 |
gr.update(value=welcome_message),
|
| 90 |
gr.update(value=format_projects_list(projects)),
|
| 91 |
gr.update(choices=get_project_choices(user_id), value=None),
|
| 92 |
+
gr.update(value=format_files_list(projects))
|
| 93 |
)
|
| 94 |
return user_state, gr.update(), gr.update()
|
| 95 |
|
|
|
|
| 113 |
gr.update(value=format_projects_list(projects)),
|
| 114 |
gr.update(choices=get_project_choices(user_id), value=project_id),
|
| 115 |
gr.Tabs(selected="logs_tab"),
|
| 116 |
+
gr.update(value=format_files_list(projects))
|
| 117 |
)
|
| 118 |
|
| 119 |
def refresh_all_projects(user_state):
|
|
|
|
| 129 |
gr.update(value=format_files_list(projects))
|
| 130 |
)
|
| 131 |
|
| 132 |
+
# NEW: Refresh files tab button
|
| 133 |
+
def refresh_files(user_state):
|
| 134 |
+
user_id = user_state.get('user_id')
|
| 135 |
+
if not user_id: return gr.update()
|
| 136 |
+
projects = get_user_projects(user_id)
|
| 137 |
+
return gr.update(value=format_files_list(projects))
|
| 138 |
+
|
| 139 |
# --- CUSTOM GENERATOR LOOPS FOR LIVE UPDATES ---
|
| 140 |
|
| 141 |
def system_stats_loop():
|
|
|
|
| 150 |
yield "⬅️ Select a project from the dropdown to see its live logs.", gr.update(visible=False)
|
| 151 |
return
|
| 152 |
|
|
|
|
| 153 |
yield "Fetching logs...", gr.update(visible=False)
|
| 154 |
|
| 155 |
while True:
|
|
|
|
| 157 |
if project:
|
| 158 |
logs = project['logs'] if project['logs'] else f"🕒 Project #{project_id} is queued or starting... Logs will appear here shortly."
|
| 159 |
|
|
|
|
| 160 |
if project['status'] == 'completed':
|
| 161 |
final_log = logs + "\n\n✅ **Project Completed!** Your file is ready for download."
|
| 162 |
zip_path = project['zip_path']
|
|
|
|
| 164 |
yield final_log, gr.update(value=zip_path, visible=True)
|
| 165 |
else:
|
| 166 |
yield logs + "\n\n⚠️ **Warning:** Project completed, but the ZIP file was not found.", gr.update(visible=False)
|
| 167 |
+
break
|
| 168 |
|
| 169 |
elif project['status'] == 'failed':
|
| 170 |
yield logs, gr.update(visible=False)
|
| 171 |
+
break
|
| 172 |
|
|
|
|
| 173 |
yield logs, gr.update(visible=False)
|
|
|
|
| 174 |
else:
|
| 175 |
yield f"Error: Project #{project_id} not found.", gr.update(visible=False)
|
| 176 |
break
|
|
|
|
| 213 |
with gr.Group(elem_classes=["logs-container"]):
|
| 214 |
logs_display = gr.Markdown("Logs will appear here in real-time.", elem_classes=["monospace"])
|
| 215 |
|
|
|
|
| 216 |
download_zip_ui = gr.File(label="Download Project ZIP", visible=False, interactive=False)
|
| 217 |
|
|
|
|
| 218 |
with gr.Tab("📁 Files", id="files_tab"):
|
| 219 |
gr.Markdown("### 📦 Download Completed Projects")
|
| 220 |
refresh_files_btn = gr.Button("🔄 Refresh Files")
|
|
|
|
| 234 |
welcome_msg,
|
| 235 |
projects_display,
|
| 236 |
project_selector,
|
| 237 |
+
files_display
|
| 238 |
]
|
| 239 |
)
|
| 240 |
|
|
|
|
| 247 |
projects_display,
|
| 248 |
project_selector,
|
| 249 |
tabs,
|
| 250 |
+
files_display
|
| 251 |
]
|
| 252 |
)
|
| 253 |
|
|
|
|
| 257 |
outputs=[
|
| 258 |
projects_display,
|
| 259 |
project_selector,
|
| 260 |
+
files_display
|
| 261 |
]
|
| 262 |
)
|
| 263 |
|
|
|
|
| 264 |
refresh_files_btn.click(
|
| 265 |
+
fn=refresh_files,
|
| 266 |
inputs=[user_state],
|
| 267 |
outputs=[files_display]
|
| 268 |
)
|
|
|
|
| 278 |
outputs=ram_monitor
|
| 279 |
)
|
| 280 |
|
|
|
|
| 281 |
demo.load(init_db, inputs=None, outputs=None, show_progress=False)
|
| 282 |
|
| 283 |
gr.HTML("""
|