Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
demo.launch()
|
|
|
|
| 1 |
+
# =========================================================
|
| 2 |
+
# NexFrame Interface for Hugging Face
|
| 3 |
+
# (visual front end only – no private RFT data)
|
| 4 |
+
# =========================================================
|
| 5 |
import gradio as gr
|
| 6 |
+
import requests, os, math, random
|
| 7 |
+
import numpy as np
|
| 8 |
+
import matplotlib.pyplot as plt
|
| 9 |
+
from io import BytesIO
|
| 10 |
+
from PIL import Image
|
| 11 |
|
| 12 |
+
API_URL = os.getenv("NEXFRAME_API_URL", "") # e.g. https://xxxx.trycloudflare.com/v1/chat
|
| 13 |
+
API_KEY = os.getenv("NEXFRAME_API_KEY", "") # your secret from Colab
|
| 14 |
|
| 15 |
+
# --- visual background generator ---
|
| 16 |
+
def cmb_wave_frame(size=256, t=0.0):
|
| 17 |
+
"""Create a red/blue coherent wave pattern."""
|
| 18 |
+
x = np.linspace(0, 4*math.pi, size)
|
| 19 |
+
y = np.linspace(0, 4*math.pi, size)
|
| 20 |
+
X, Y = np.meshgrid(x, y)
|
| 21 |
+
Z = np.sin(X + t) * np.cos(Y - t/2)
|
| 22 |
+
img = np.zeros((size, size, 3), dtype=np.uint8)
|
| 23 |
+
img[...,0] = ((Z+1)/2*255).astype(np.uint8) # red
|
| 24 |
+
img[...,2] = ((1-Z)/2*255).astype(np.uint8) # blue
|
| 25 |
+
return Image.fromarray(img)
|
| 26 |
+
|
| 27 |
+
# --- local animation cache (first frame only) ---
|
| 28 |
+
def cmb_background():
|
| 29 |
+
frame = cmb_wave_frame(size=256, t=random.random()*6.28)
|
| 30 |
+
buf = BytesIO()
|
| 31 |
+
frame.save(buf, format="PNG")
|
| 32 |
+
return buf.getvalue()
|
| 33 |
+
|
| 34 |
+
# --- chat function (offline by default) ---
|
| 35 |
+
def chat_with_nexframe(message):
|
| 36 |
+
if not API_URL:
|
| 37 |
+
# offline demo mode
|
| 38 |
+
return "🧠 NexFrame is dormant. Start your Colab API and set NEXFRAME_API_URL.", cmb_background()
|
| 39 |
+
try:
|
| 40 |
+
r = requests.post(API_URL,
|
| 41 |
+
headers={"X-API-Key": API_KEY},
|
| 42 |
+
json={"query": message, "k": 6}, timeout=30)
|
| 43 |
+
data = r.json()
|
| 44 |
+
answer = data.get("answer") or str(data)
|
| 45 |
+
except Exception as e:
|
| 46 |
+
answer = f"[Connection error: {e}]"
|
| 47 |
+
return answer, cmb_background()
|
| 48 |
+
|
| 49 |
+
# --- build interface ---
|
| 50 |
+
with gr.Blocks(css="""
|
| 51 |
+
body {background: black;}
|
| 52 |
+
""") as demo:
|
| 53 |
+
gr.HTML("<h1 style='color:white;text-align:center;'>🧬 NexFrame Conscious Matrix</h1>")
|
| 54 |
+
with gr.Row():
|
| 55 |
+
user_in = gr.Textbox(label="Your Input", placeholder="Type a question or message...", lines=2)
|
| 56 |
+
with gr.Row():
|
| 57 |
+
output = gr.Textbox(label="NexFrame Output", lines=8)
|
| 58 |
+
image_box = gr.Image(label="CMB-like Coherence Field", type="numpy")
|
| 59 |
+
btn = gr.Button("Send to NexFrame", variant="primary")
|
| 60 |
+
btn.click(chat_with_nexframe, inputs=user_in, outputs=[output, image_box])
|
| 61 |
|
| 62 |
demo.launch()
|