Spaces:
Sleeping
Sleeping
| 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(""" | |
| <div style='display: flex; gap: 5px; flex-wrap: wrap;'> | |
| <span class='app-badge' style='background:#f24e1e; color:white;'>FIGMA</span> | |
| <span class='app-badge' style='background:#4285f4; color:white;'>CALENDAR</span> | |
| <span class='app-badge' style='background:#000000; color:white;'>NOTION</span> | |
| <span class='app-badge' style='background:#34a853; color:white;'>SHEETS</span> | |
| <span class='app-badge' style='background:#fbbc04; color:black;'>SLIDES</span> | |
| <span class='app-badge' style='background:#6366f1; color:white;'>FILES</span> | |
| </div> | |
| """) | |
| # Events | |
| btn_1.click(lambda: "Schedule a meeting for tomorrow at 2 PM.", None, user_input) | |
| btn_2.click(lambda: "Analyze the Figma design for any color contrast issues.", None, user_input) | |
| btn_3.click(lambda: "Create a new Notion page for the EAM v1.2 Release Notes.", None, user_input) | |
| run_btn.click( | |
| fn=beginner_inference, | |
| inputs=user_input, | |
| outputs=[current_status, progress_detail] | |
| ) | |
| gr.Markdown("---") | |
| gr.Markdown("Built with **BitNet 1.58b** & **Memory Sparse Attention**. Part of the EAM-100M Intelligent Kernel Project.") | |
| if __name__ == "__main__": | |
| demo.launch() | |
| # Deploy timestamp: 1778163251.6163218 | |