Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import torch
|
| 3 |
-
import psutil
|
| 4 |
from backend import (
|
| 5 |
create_user,
|
| 6 |
get_user_by_username,
|
|
@@ -11,7 +9,8 @@ from backend import (
|
|
| 11 |
queue_job,
|
| 12 |
get_project
|
| 13 |
)
|
| 14 |
-
|
|
|
|
| 15 |
user_state = {"user_id": None, "username": ""}
|
| 16 |
|
| 17 |
def page_login(username, password):
|
|
@@ -45,7 +44,7 @@ def page_projects():
|
|
| 45 |
def start_new_project(prompt):
|
| 46 |
if not user_state["user_id"]:
|
| 47 |
return "❌ Please login first.", "", "", ""
|
| 48 |
-
|
| 49 |
projects = get_user_projects(user_state["user_id"])
|
| 50 |
if len(projects) >= 3:
|
| 51 |
return "⚠️ You can only have 3 projects. Delete one to create another.", "", "", ""
|
|
@@ -53,7 +52,12 @@ def start_new_project(prompt):
|
|
| 53 |
project_id = create_project(user_state["user_id"], "New Project", prompt)
|
| 54 |
queue_job(project_id, user_state["user_id"], prompt)
|
| 55 |
|
| 56 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
def search_projects_ui(query):
|
| 59 |
if not user_state["user_id"]:
|
|
@@ -66,8 +70,14 @@ def search_projects_ui(query):
|
|
| 66 |
for p in results
|
| 67 |
])
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
def show_agent_logs(project_id):
|
| 70 |
-
if not project_id:
|
| 71 |
return "No project selected."
|
| 72 |
project = get_project(project_id)
|
| 73 |
if not project:
|
|
@@ -112,22 +122,40 @@ with gr.Blocks(title="Code Agents Pro") as demo:
|
|
| 112 |
# ---- PAGE 3: AGENT CONVERSATION LOGS ----
|
| 113 |
with gr.Group(visible=False) as page_logs_ui:
|
| 114 |
gr.Markdown("### 🧠 Agent Conversation Logs")
|
| 115 |
-
project_selector = gr.Dropdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
view_logs_btn = gr.Button("👁️ View Full Conversation")
|
| 117 |
-
logs_display = gr.Markdown(
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
-
#
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
| 131 |
|
| 132 |
# ------------------------------ EVENTS ------------------------------
|
| 133 |
|
|
@@ -157,7 +185,7 @@ with gr.Blocks(title="Code Agents Pro") as demo:
|
|
| 157 |
outputs=[projects_display, search_results]
|
| 158 |
)
|
| 159 |
|
| 160 |
-
# Switch to logs tab
|
| 161 |
start_btn.click(
|
| 162 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 163 |
outputs=[page_logs_ui, page_main_ui]
|
|
@@ -170,4 +198,20 @@ with gr.Blocks(title="Code Agents Pro") as demo:
|
|
| 170 |
outputs=[page_logs_ui, page_main_ui]
|
| 171 |
)
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
demo.queue().launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from backend import (
|
| 3 |
create_user,
|
| 4 |
get_user_by_username,
|
|
|
|
| 9 |
queue_job,
|
| 10 |
get_project
|
| 11 |
)
|
| 12 |
+
import psutil
|
| 13 |
+
import torch
|
| 14 |
user_state = {"user_id": None, "username": ""}
|
| 15 |
|
| 16 |
def page_login(username, password):
|
|
|
|
| 44 |
def start_new_project(prompt):
|
| 45 |
if not user_state["user_id"]:
|
| 46 |
return "❌ Please login first.", "", "", ""
|
| 47 |
+
|
| 48 |
projects = get_user_projects(user_state["user_id"])
|
| 49 |
if len(projects) >= 3:
|
| 50 |
return "⚠️ You can only have 3 projects. Delete one to create another.", "", "", ""
|
|
|
|
| 52 |
project_id = create_project(user_state["user_id"], "New Project", prompt)
|
| 53 |
queue_job(project_id, user_state["user_id"], prompt)
|
| 54 |
|
| 55 |
+
return (
|
| 56 |
+
f"✅ Project #{project_id} started! You can leave this page — we'll notify you when it's ready.",
|
| 57 |
+
"",
|
| 58 |
+
"",
|
| 59 |
+
gr.update(value=f"✅ Project #{project_id} started! Now go to ‘Agent Conversation’ → click ‘Load My Projects’ to see logs.")
|
| 60 |
+
)
|
| 61 |
|
| 62 |
def search_projects_ui(query):
|
| 63 |
if not user_state["user_id"]:
|
|
|
|
| 70 |
for p in results
|
| 71 |
])
|
| 72 |
|
| 73 |
+
def update_dropdown():
|
| 74 |
+
if not user_state["user_id"]:
|
| 75 |
+
return []
|
| 76 |
+
projects = get_user_projects(user_state["user_id"], limit=10)
|
| 77 |
+
return [(f"[{p[0]}] {p[1]}", p[0]) for p in projects]
|
| 78 |
+
|
| 79 |
def show_agent_logs(project_id):
|
| 80 |
+
if not project_id or project_id == "":
|
| 81 |
return "No project selected."
|
| 82 |
project = get_project(project_id)
|
| 83 |
if not project:
|
|
|
|
| 122 |
# ---- PAGE 3: AGENT CONVERSATION LOGS ----
|
| 123 |
with gr.Group(visible=False) as page_logs_ui:
|
| 124 |
gr.Markdown("### 🧠 Agent Conversation Logs")
|
| 125 |
+
project_selector = gr.Dropdown(
|
| 126 |
+
label="Select Project",
|
| 127 |
+
choices=[],
|
| 128 |
+
interactive=True,
|
| 129 |
+
allow_custom_value=False
|
| 130 |
+
)
|
| 131 |
+
refresh_dropdown_btn = gr.Button("🔄 Load My Projects")
|
| 132 |
view_logs_btn = gr.Button("👁️ View Full Conversation")
|
| 133 |
+
logs_display = gr.Markdown(
|
| 134 |
+
label="Agent Messages",
|
| 135 |
+
value="",
|
| 136 |
+
height=600,
|
| 137 |
+
elem_classes=["monospace"]
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
# When user clicks "Load My Projects", populate dropdown
|
| 141 |
+
refresh_dropdown_btn.click(
|
| 142 |
+
fn=update_dropdown,
|
| 143 |
+
inputs=None,
|
| 144 |
+
outputs=project_selector
|
| 145 |
+
)
|
| 146 |
|
| 147 |
+
# When user selects a project, show logs
|
| 148 |
+
project_selector.change(
|
| 149 |
+
fn=show_agent_logs,
|
| 150 |
+
inputs=project_selector,
|
| 151 |
+
outputs=logs_display
|
| 152 |
+
)
|
| 153 |
|
| 154 |
+
view_logs_btn.click(
|
| 155 |
+
fn=show_agent_logs,
|
| 156 |
+
inputs=project_selector,
|
| 157 |
+
outputs=logs_display
|
| 158 |
+
)
|
| 159 |
|
| 160 |
# ------------------------------ EVENTS ------------------------------
|
| 161 |
|
|
|
|
| 185 |
outputs=[projects_display, search_results]
|
| 186 |
)
|
| 187 |
|
| 188 |
+
# Switch to logs tab after starting project
|
| 189 |
start_btn.click(
|
| 190 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 191 |
outputs=[page_logs_ui, page_main_ui]
|
|
|
|
| 198 |
outputs=[page_logs_ui, page_main_ui]
|
| 199 |
)
|
| 200 |
|
| 201 |
+
# Add monospace CSS
|
| 202 |
+
gr.HTML("""
|
| 203 |
+
<style>
|
| 204 |
+
.monospace {
|
| 205 |
+
font-family: 'Courier New', Courier, monospace;
|
| 206 |
+
font-size: 14px;
|
| 207 |
+
white-space: pre-wrap;
|
| 208 |
+
word-wrap: break-word;
|
| 209 |
+
background-color: #f4f4f4;
|
| 210 |
+
padding: 10px;
|
| 211 |
+
border-radius: 5px;
|
| 212 |
+
margin-top: 10px;
|
| 213 |
+
}
|
| 214 |
+
</style>
|
| 215 |
+
""")
|
| 216 |
+
|
| 217 |
demo.queue().launch(server_name="0.0.0.0", server_port=7860)
|