"""Gradio Chat UI for Aethron Portfolio Agent — ZeroGPU-compatible.""" import spaces # noqa: E402 — MUST BE FIRST import os import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) import gradio as gr print("=" * 55) print("AETHRON PORTFOLIO AGENT — GPU Mode (ZeroGPU)") print("=" * 55) # Pipeline loaded lazily inside @spaces.GPU context — avoids CUDA init in main process _pipeline = None def get_pipeline(): global _pipeline if _pipeline is None: from rag_pipeline import AethronPipeline print("Loading pipeline (first query)...") _pipeline = AethronPipeline( build_index=not os.path.exists("data/index/faiss.index") ) return _pipeline @spaces.GPU(duration=60) def respond(message, history): """Handle chat — runs inside GPU context so torch.cuda patches apply.""" if not message or not message.strip(): return history pipeline = get_pipeline() result = pipeline.query(message.strip()) response = result["answer"] if result["sources"]: source_names = [s.replace("_", " ").title() for s in result["sources"][:5]] response += "\n\n**Sources:** " + " | ".join(source_names) history.append({"role": "user", "content": message}) history.append({"role": "assistant", "content": response}) return history CUSTOM_CSS = """ .container { max-width: 900px; margin: auto; } .header { text-align: center; padding: 20px; } .header h1 { color: #1a1a2e; font-family: 'Segoe UI', sans-serif; } .header p { color: #4a4a6a; } """ with gr.Blocks(title="Aethron | Chat with Arash's Portfolio") as demo: gr.HTML("""
Neuro-Symbolic Portfolio Agent — Ask about Arash Nicoomanesh's experience, architecture, and projects
Portfolio | GitHub | Kaggle | HuggingFace
Powered by Type 2 Neuro-Symbolic RAG | Phi-3.5-mini + BGE-small + FAISS | Running on Hugging Face Spaces
""") if __name__ == "__main__": demo.launch( server_name="0.0.0.0", server_port=7860, show_error=True, css=CUSTOM_CSS, )