Spaces:
Sleeping
Sleeping
Graham Paasch commited on
Commit ·
e667ba8
1
Parent(s): ad6849b
Temporarily disable consultation UI due to Gradio 4.44.0 schema bug
Browse files
app.py
CHANGED
|
@@ -238,163 +238,13 @@ def build_ui():
|
|
| 238 |
gr.Markdown("---")
|
| 239 |
|
| 240 |
# ===== INTERACTIVE CONSULTATION TAB =====
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
with gr.Column(elem_classes=["og-panel"]):
|
| 249 |
-
gr.Markdown("#### 🤝 Consultation Chat")
|
| 250 |
-
consultation_chat = gr.Chatbot(
|
| 251 |
-
label="AI Network Consultant",
|
| 252 |
-
value=[],
|
| 253 |
-
height=400,
|
| 254 |
-
show_label=False,
|
| 255 |
-
)
|
| 256 |
-
consultation_input = gr.Textbox(
|
| 257 |
-
label="Your message",
|
| 258 |
-
placeholder="Hi, I need help designing a network for my small business...",
|
| 259 |
-
lines=2,
|
| 260 |
-
)
|
| 261 |
-
with gr.Row():
|
| 262 |
-
send_consultation_btn = gr.Button("📤 Send", variant="primary")
|
| 263 |
-
start_new_consultation_btn = gr.Button("🔄 New Consultation", variant="secondary")
|
| 264 |
-
use_consultation_btn = gr.Button("✅ Use This for Pipeline", variant="primary")
|
| 265 |
-
|
| 266 |
-
consultation_summary = gr.Textbox(
|
| 267 |
-
label="Consultation Summary (will be used in pipeline)",
|
| 268 |
-
lines=5,
|
| 269 |
-
interactive=False,
|
| 270 |
-
)
|
| 271 |
-
|
| 272 |
-
# Consultation state - use None as default to avoid Gradio schema issues
|
| 273 |
-
consultation_state = gr.State(value=None)
|
| 274 |
-
|
| 275 |
-
def start_consultation():
|
| 276 |
-
"""Initialize a new consultation"""
|
| 277 |
-
return None, [], ""
|
| 278 |
-
|
| 279 |
-
def send_consultation_message(user_message, state):
|
| 280 |
-
"""Send a message in the consultation"""
|
| 281 |
-
if not user_message.strip():
|
| 282 |
-
# Return empty if no message
|
| 283 |
-
if state and isinstance(state, dict):
|
| 284 |
-
consultant = state.get("consultant")
|
| 285 |
-
if consultant and hasattr(consultant, 'conversation_history'):
|
| 286 |
-
# Convert conversation history to chatbot format
|
| 287 |
-
chatbot_messages = []
|
| 288 |
-
for msg in consultant.conversation_history:
|
| 289 |
-
if msg.role == "user" and not msg.content.startswith("Initial request:"):
|
| 290 |
-
chatbot_messages.append((msg.content, None))
|
| 291 |
-
elif msg.role == "assistant" and chatbot_messages:
|
| 292 |
-
# Pair with previous user message
|
| 293 |
-
if chatbot_messages[-1][1] is None:
|
| 294 |
-
chatbot_messages[-1] = (chatbot_messages[-1][0], msg.content)
|
| 295 |
-
else:
|
| 296 |
-
chatbot_messages.append((None, msg.content))
|
| 297 |
-
return state, chatbot_messages, ""
|
| 298 |
-
return state, [], ""
|
| 299 |
-
|
| 300 |
-
from agent.consultation import NetworkConsultant
|
| 301 |
-
|
| 302 |
-
# Initialize state if needed
|
| 303 |
-
if not state:
|
| 304 |
-
state = {}
|
| 305 |
-
|
| 306 |
-
# Get or create consultant
|
| 307 |
-
consultant = state.get("consultant")
|
| 308 |
-
first_message = consultant is None
|
| 309 |
-
|
| 310 |
-
if first_message:
|
| 311 |
-
consultant = NetworkConsultant()
|
| 312 |
-
state["consultant"] = consultant
|
| 313 |
-
# Start consultation with user's first message
|
| 314 |
-
is_complete, response, intent_data = consultant.start_consultation(user_message)
|
| 315 |
-
else:
|
| 316 |
-
# Continue existing consultation
|
| 317 |
-
is_complete, response, intent_data = consultant.continue_consultation(user_message)
|
| 318 |
-
|
| 319 |
-
# Update completion state
|
| 320 |
-
state["is_complete"] = is_complete
|
| 321 |
-
if is_complete and intent_data:
|
| 322 |
-
state["intent_data"] = intent_data
|
| 323 |
-
|
| 324 |
-
# Build chatbot display from conversation history
|
| 325 |
-
chatbot_messages = []
|
| 326 |
-
for msg in consultant.conversation_history:
|
| 327 |
-
# Skip system messages and "Initial request:" prefix
|
| 328 |
-
if msg.role == "system":
|
| 329 |
-
continue
|
| 330 |
-
if msg.role == "user":
|
| 331 |
-
content = msg.content
|
| 332 |
-
if content.startswith("Initial request: "):
|
| 333 |
-
content = content[len("Initial request: "):]
|
| 334 |
-
chatbot_messages.append((content, None))
|
| 335 |
-
elif msg.role == "assistant":
|
| 336 |
-
# Pair with the last user message
|
| 337 |
-
if chatbot_messages and chatbot_messages[-1][1] is None:
|
| 338 |
-
chatbot_messages[-1] = (chatbot_messages[-1][0], msg.content)
|
| 339 |
-
else:
|
| 340 |
-
# Standalone assistant message (shouldn't happen normally)
|
| 341 |
-
chatbot_messages.append((None, msg.content))
|
| 342 |
-
|
| 343 |
-
return state, chatbot_messages, ""
|
| 344 |
-
|
| 345 |
-
def use_consultation_summary(state):
|
| 346 |
-
"""Extract the consultation summary for use in the pipeline"""
|
| 347 |
-
if not state or not isinstance(state, dict):
|
| 348 |
-
return "No consultation history yet. Start a conversation first!"
|
| 349 |
-
|
| 350 |
-
consultant = state.get("consultant")
|
| 351 |
-
if not consultant or not consultant.conversation_history:
|
| 352 |
-
return "No consultation history yet. Start a conversation first!"
|
| 353 |
-
|
| 354 |
-
# If consultation is complete, use the structured intent
|
| 355 |
-
if state.get("is_complete") and state.get("intent_data"):
|
| 356 |
-
intent = state["intent_data"]
|
| 357 |
-
summary = "# Consultation Summary (Complete)\n\n"
|
| 358 |
-
for key, value in intent.items():
|
| 359 |
-
summary += f"**{key}:** {value}\n\n"
|
| 360 |
-
return summary
|
| 361 |
-
|
| 362 |
-
# Otherwise, combine all messages into a summary
|
| 363 |
-
summary = "# Consultation Summary (In Progress)\n\n"
|
| 364 |
-
for msg in consultant.conversation_history:
|
| 365 |
-
if msg.role == "system":
|
| 366 |
-
continue
|
| 367 |
-
prefix = "**You:** " if msg.role == "user" else "**AI:** "
|
| 368 |
-
content = msg.content
|
| 369 |
-
if content.startswith("Initial request: "):
|
| 370 |
-
content = content[len("Initial request: "):]
|
| 371 |
-
summary += f"{prefix}{content}\n\n"
|
| 372 |
-
|
| 373 |
-
return summary
|
| 374 |
-
|
| 375 |
-
# Wire up consultation handlers
|
| 376 |
-
start_new_consultation_btn.click(
|
| 377 |
-
fn=start_consultation,
|
| 378 |
-
outputs=[consultation_state, consultation_chat, consultation_input]
|
| 379 |
-
)
|
| 380 |
-
|
| 381 |
-
send_consultation_btn.click(
|
| 382 |
-
fn=send_consultation_message,
|
| 383 |
-
inputs=[consultation_input, consultation_state],
|
| 384 |
-
outputs=[consultation_state, consultation_chat, consultation_input]
|
| 385 |
-
)
|
| 386 |
-
|
| 387 |
-
consultation_input.submit(
|
| 388 |
-
fn=send_consultation_message,
|
| 389 |
-
inputs=[consultation_input, consultation_state],
|
| 390 |
-
outputs=[consultation_state, consultation_chat, consultation_input]
|
| 391 |
-
)
|
| 392 |
-
|
| 393 |
-
use_consultation_btn.click(
|
| 394 |
-
fn=use_consultation_summary,
|
| 395 |
-
inputs=[consultation_state],
|
| 396 |
-
outputs=[consultation_summary]
|
| 397 |
-
)
|
| 398 |
|
| 399 |
gr.Markdown("---")
|
| 400 |
|
|
|
|
| 238 |
gr.Markdown("---")
|
| 239 |
|
| 240 |
# ===== INTERACTIVE CONSULTATION TAB =====
|
| 241 |
+
# Temporarily disabled due to Gradio 4.44.0 schema bug
|
| 242 |
+
# TODO: Re-enable when upgrading to Gradio 4.44.1+
|
| 243 |
+
# gr.Markdown("""### 💬 Interactive Consultation
|
| 244 |
+
# **Have a conversation before running the full pipeline**
|
| 245 |
+
#
|
| 246 |
+
# Not sure what you need? Start here! The AI will ask clarifying questions to understand your network requirements.
|
| 247 |
+
# """)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
gr.Markdown("---")
|
| 250 |
|