import gradio as gr import torch from model.nano_gpt import AgentGPT, Config from agent.recursive_reasoning import RecursiveAgenticLoop import tiktoken import time # 1. Setup Kernel config = Config() config.n_layer = 10 config.n_embd = 640 model = AgentGPT(config) model.eval() class TiktokenWrapper: def __init__(self): self.enc = tiktoken.get_encoding("cl100k_base") def encode(self, t, **kwargs): ids = self.enc.encode(t) if kwargs.get('return_tensors') == 'pt': return torch.tensor([ids]) return ids def decode(self, i): if hasattr(i, 'tolist'): i = i.tolist() return self.enc.decode(i) tokenizer = TiktokenWrapper() agent = RecursiveAgenticLoop(model, tokenizer, demo_mode=True) def beginner_inference(prompt): # Simulation for a smooth beginner experience in HF Spaces yield "🤖 Thinking...", "I'm analyzing your request..." time.sleep(1) if any(kw in prompt.lower() for kw in ["meet", "calendar", "schedule"]): yield "📅 Accessing Google Calendar...", "Checking for availability..." time.sleep(1) yield "✅ Event Scheduled", f"I've added the meeting to your calendar." elif any(kw in prompt.lower() for kw in ["design", "figma"]): yield "🎨 Fetching Figma Data...", "Scanning layers and components..." time.sleep(1) yield "✅ Design Analyzed", "I've extracted the UI tokens from your Figma file." elif "notion" in prompt.lower(): yield "📝 Syncing with Notion...", "Creating a new page in your workspace..." time.sleep(1) yield "✅ Page Created", "Your Notion workspace has been updated." else: # Fallback to the real reasoning engine response = agent.generate_with_reasoning(prompt) yield "✅ Task Complete", response # 2. Build Premium Beginner UI for HF with gr.Blocks(theme=gr.themes.Soft(), css=""" .beginner-card { border-radius: 15px; padding: 20px; background: white; border: 1px solid #e5e7eb; margin-bottom: 20px; } .status-msg { font-size: 1.4rem; font-weight: 700; color: #4f46e5; } .app-badge { display: inline-block; padding: 4px 10px; border-radius: 6px; font-size: 0.75rem; font-weight: bold; margin: 2px; } """) as demo: gr.Markdown("# 🧠 EAM-100M: Your Workspace Agent (v1.2.1-LIVE)") gr.Markdown("### *Powerful reasoning in a tiny package. Control your apps with simple commands.*") with gr.Row(): with gr.Column(scale=2): with gr.Group(elem_classes=["beginner-card"]): gr.Markdown("### 💬 What do you need help with?") user_input = gr.Textbox( show_label=False, placeholder="e.g., 'Schedule a meeting' or 'Create a Notion page'", lines=2 ) run_btn = gr.Button("Execute Command", variant="primary") gr.Markdown("### 💡 Try these:") with gr.Row(): btn_1 = gr.Button("📅 Schedule Meet", size="sm") btn_2 = gr.Button("🎨 Analyze Figma", size="sm") btn_3 = gr.Button("📝 Notion Sync", size="sm") with gr.Column(scale=3): with gr.Group(elem_classes=["beginner-card"]): gr.Markdown("### ⚡ Current Activity") current_status = gr.Markdown("Waiting for command...", elem_classes=["status-msg"]) progress_detail = gr.Markdown("Ready to assist in your workspace.") with gr.Group(elem_classes=["beginner-card"]): gr.Markdown("### 🔌 Integrated Apps") gr.HTML("""