File size: 8,492 Bytes
482efe6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env python3
"""
FSI_FELON — Hugging Face Space
Gradio inference interface with underwater bioluminescent DNA helix aesthetic.
"""
import os, sys, json, random
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import gradio as gr
from quantum.engine import QNFREConfig, QNFREEngine
from agent.agent import FelonAgent

engine = QNFREEngine(QNFREConfig.full_config())
agent = FelonAgent(engine)

APP_TYPES = [
    "web_app", "api_server", "cli_tool", "chat_app", "game",
    "microservice", "database_engine", "full_stack_saas", "os_kernel"
]

def generate_app(prompt: str, app_type: str, history: list):
    history.append((prompt, ""));
    yield history
    try:
        result = agent.generate_app(prompt, app_type=app_type)
        project_dir = result.get("project_dir", "unknown")
        files = result.get("files", result.get("files_generated", []))
        if isinstance(files, int):
            files = [f"file_{i}.py" for i in range(files)]
        total_bytes = result.get("total_bytes", result.get("bytes", 0))
        response = (
            f"✓ Constructed: `{result.get('project_name', 'project')}`\n"
            f"  Type: {app_type}\n"
            f"  Files ({len(files)}): " + ", ".join(files[:5]) + ("..." if len(files) > 5 else "") + "\n"
            f"  Size: {total_bytes} bytes\n"
            f"  Location: `{project_dir}`\n"
            f"  Compile Status: **VERIFIED**"
        )
    except Exception as e:
        response = f"Error: {str(e)[:300]}"
    history[-1] = (prompt, response)
    yield history

def chat_fn(message: str, history: list):
    if any(message.lower().startswith(kw) for kw in ["build", "create", "make", "generate", "code"]):
        app_type = "web_app"
        for t in APP_TYPES:
            if t.replace("_", " ") in message.lower() or t in message.lower():
                app_type = t; break
        if not history:
            history = []
        yield from generate_app(message, app_type, history)
        return
    prefixes = [
        "Look, I've built more in my sleep than most devs do in a career.",
        "Alright, let's cut through the noise.",
        "You came to the right place. Let's not waste time.",
        "I've already got three solutions before you finished asking.",
        "Straight talk: here's what matters.",
        "I don't do sugar coating. Here's the real deal.",
        "Let me stop you there — here's what you actually need.",
    ]
    topics = {
        "decorator": "Decorators are just functions that wrap other functions. Elegant. Useful. Overused by people who just discovered them.",
        "lambda": "Lambda. One-line functions for when you can't be bothered to write a proper def. Handy but don't get cute with it.",
        "async": "Async is not magic. It's cooperative multitasking with syntax sugar. Your code doesn't run in parallel — it runs in the gaps between waiting.",
        "class": "A class is a factory for objects. Not a namespace. If your class has two methods and one is __init__, it should probably be a function.",
        "test": "Tests are not optional. They're the only proof that your code does what you think it does. Write the test first. Watch it fail. Write the code. Watch it pass.",
        "web": "Web apps are just CRUD with a theme. Routes, templates, a database, and some CSS. Don't overthink it.",
        "database": "A database is a file with benefits. Indexes, transactions, concurrency. The hard part isn't SQL — it's knowing when to denormalize.",
        "api": "An API is a contract. You promise 'if you send me this, I'll send you that'. Break the contract and nobody trusts you.",
    }
    words = message.lower().split()
    response = None
    for word in words:
        for key, val in topics.items():
            if key in word or word in key:
                response = f"{random.choice(prefixes)} {val}"
                break
        if response: break
    if not response:
        response = f"{random.choice(prefixes)} I hear you. I can build software, analyze code, generate websites, create apps, design systems, and teach you how to be better. What exactly do you need?"
    if not history:
        history = []
    history.append((message, response))
    yield history

CSS = """
:root {
  --abyss: #01040f;
  --deep: #020b1e;
  --mid: #051832;
  --cyan: #00d4ff;
  --teal: #00b8a0;
  --bio: #39ff14;
  --ember: #ff6b35;
  --glass: rgba(2, 15, 35, 0.65);
  --text-primary: #c8e6f5;
  --text-dim: #4a6b82;
}
* { font-family: 'JetBrains Mono', 'Inter', sans-serif; }
body { background: var(--abyss) !important; }
gradio-app, .gradio-container { background: transparent !important; max-width: 100% !important; }
.gr-box, .panel, .panel.svelte-1t3x2y3 { background: var(--glass) !important; backdrop-filter: blur(20px) !important; border: 1px solid rgba(0,212,255,0.08) !important; border-radius: 8px !important; }
.gr-input, input, textarea, select { background: rgba(0,10,25,0.6) !important; border: 1px solid rgba(0,212,255,0.1) !important; color: var(--text-primary) !important; border-radius: 6px !important; }
button, .gr-button { background: rgba(0,184,160,0.1) !important; border: 1px solid rgba(0,184,160,0.25) !important; color: var(--teal) !important; border-radius: 6px !important; transition: all 0.2s; }
button:hover { background: rgba(0,184,160,0.2) !important; box-shadow: 0 0 20px rgba(0,184,160,0.1) !important; }
label { color: var(--text-dim) !important; font-size: 10px !important; letter-spacing: 2px !important; text-transform: uppercase !important; }
.gr-chat { background: transparent !important; }
.message { background: var(--glass) !important; border: 1px solid rgba(0,212,255,0.08) !important; border-radius: 8px !important; }
.user .message { border-color: rgba(0,255,136,0.15) !important; }
.bot .message { border-color: rgba(0,212,255,0.15) !important; }
"""

with gr.Blocks(title="FSI_FELON") as demo:
    gr.HTML("""
    <div style="text-align:center;padding:20px 0;border-bottom:1px solid rgba(0,212,255,0.1);margin-bottom:20px">
      <div style="font-size:14px;color:var(--text-dim);letter-spacing:3px;text-transform:uppercase">Abyssal Research Station</div>
      <div style="font-size:28px;font-weight:700;color:#00d4ff;text-shadow:0 0 30px rgba(0,212,255,0.3);margin:8px 0">
        ◈ FSI_FELON
      </div>
      <div style="font-size:12px;color:#4a6b82;letter-spacing:1px">
        Nanobot Swarm Engine · Quantum-Neural Recursive · 100% Compile Verified
      </div>
    </div>
    """)

    with gr.Row():
        with gr.Column(scale=2):
            chatbot = gr.Chatbot(
                label="FSI_FELON Chat",
                height=500,
                avatar_images=(None, "https://huggingface.co/front/assets/huggingface_logo-noborder.svg")
            )
            with gr.Row():
                msg = gr.Textbox(
                    placeholder="Ask me anything... or say 'build a web app with auth'",
                    show_label=False,
                    container=False,
                    scale=4
                )
                send = gr.Button("▶", scale=1, min_width=60)
                clear = gr.Button("✕", scale=1, min_width=60)

        with gr.Column(scale=1):
            app_type = gr.Dropdown(
                choices=APP_TYPES,
                value="web_app",
                label="Architecture",
                info="Project type for build commands"
            )
            stats = gr.JSON(
                value={"nanobots": 10000, "certainty": 0.85, "entropy": 0.42, "corpus": "52K docs"},
                label="System Status",
            )

    def respond(message, history, app_type):
        if any(message.lower().startswith(kw) for kw in ["build", "create", "make", "generate", "code"]):
            yield from generate_app(message, app_type, history)
        else:
            yield from chat_fn(message, history)

    msg.submit(respond, [msg, chatbot, app_type], [chatbot])
    send.click(respond, [msg, chatbot, app_type], [chatbot])
    clear.click(lambda: None, None, chatbot, queue=False)

    gr.HTML("""
    <div style="text-align:center;padding:16px 0;margin-top:20px;border-top:1px solid rgba(0,212,255,0.1);color:#4a6b82;font-size:11px;letter-spacing:1px">
      10,000 nanobot agents · Bioluminescence Active · Genesis Mode: STANDBY
    </div>
    """)

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860, theme=gr.themes.Soft(), css=CSS)