import gradio as gr import uuid import sys import os import traceback # Add project root to Python path sys.path.append( os.path.abspath( os.path.join( os.path.dirname(__file__), ".." ) ) ) from backend import Agent def chat_with_agent(message, history, session_id): """ Directly calls Agent.run_agent() and prints detailed errors to HF Space logs. """ try: response = Agent.run_agent( message=message, session_id=session_id ) return response except Exception as e: error_trace = traceback.format_exc() print("\n" + "=" * 80) print("SMART SUPPORT AI ERROR") print("=" * 80) print(error_trace) print("=" * 80 + "\n") return ( f"⚠️ Error Type: {type(e).__name__}\n\n" f"Error Message:\n{str(e)}" ) with gr.Blocks( title="SmartSupport AI", theme=gr.themes.Soft() ) as demo: gr.Markdown( """ # 🤖 SmartSupport AI Desk Welcome to the customer support portal. This assistant can: - Search the knowledge base - Answer customer questions - Create support tickets - Escalate issues to human agents """ ) session_id = gr.State(str(uuid.uuid4())) gr.ChatInterface( fn=chat_with_agent, additional_inputs=[session_id], chatbot=gr.Chatbot( height=500, type="messages" ), textbox=gr.Textbox( placeholder="Type your message here...", container=False, scale=7 ), type="messages" ) if __name__ == "__main__": demo.launch( server_name="0.0.0.0" )