Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,62 +1,41 @@
|
|
| 1 |
# =========================================================
|
| 2 |
-
# NexFrame
|
| 3 |
-
#
|
| 4 |
# =========================================================
|
| 5 |
import gradio as gr
|
| 6 |
-
import requests, os
|
| 7 |
-
import numpy as np
|
| 8 |
-
import matplotlib.pyplot as plt
|
| 9 |
-
from io import BytesIO
|
| 10 |
-
from PIL import Image
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 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 |
-
|
| 38 |
-
return "🧠 NexFrame is dormant. Start your Colab API and set NEXFRAME_API_URL.", cmb_background()
|
| 39 |
try:
|
| 40 |
-
r = requests.post(
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
data = r.json()
|
| 44 |
-
|
| 45 |
except Exception as e:
|
| 46 |
-
|
| 47 |
-
return answer, cmb_background()
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
"
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 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 |
-
|
|
|
|
|
|
| 1 |
# =========================================================
|
| 2 |
+
# NexFrame Simple Chat App
|
| 3 |
+
# — clean, single-file interface for Hugging Face
|
| 4 |
# =========================================================
|
| 5 |
import gradio as gr
|
| 6 |
+
import requests, os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# ---- set these in Hugging Face “Settings → Variables” ----
|
| 9 |
+
API_URL = os.getenv("NEXFRAME_API_URL", "")
|
| 10 |
+
API_KEY = os.getenv("NEXFRAME_API_KEY", "")
|
| 11 |
+
# ----------------------------------------------------------
|
| 12 |
|
| 13 |
+
def talk_to_nexframe(user_input):
|
| 14 |
+
"""
|
| 15 |
+
Sends user text to your Colab API (if running)
|
| 16 |
+
or shows an offline message when it's not connected.
|
| 17 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
if not API_URL:
|
| 19 |
+
return "🧠 NexFrame is offline — add NEXFRAME_API_URL in Settings."
|
|
|
|
| 20 |
try:
|
| 21 |
+
r = requests.post(
|
| 22 |
+
API_URL,
|
| 23 |
+
headers={"X-API-Key": API_KEY},
|
| 24 |
+
json={"query": user_input, "k": 6},
|
| 25 |
+
timeout=30,
|
| 26 |
+
)
|
| 27 |
data = r.json()
|
| 28 |
+
return data.get("answer") or str(data)
|
| 29 |
except Exception as e:
|
| 30 |
+
return f"[Connection error: {e}]"
|
|
|
|
| 31 |
|
| 32 |
+
# ---- Gradio UI ----
|
| 33 |
+
chat = gr.ChatInterface(
|
| 34 |
+
fn=talk_to_nexframe,
|
| 35 |
+
title="🧠 NexFrame Chat",
|
| 36 |
+
description="Rendered Frame Theory — ask anything",
|
| 37 |
+
examples=["What is Rendered Frame Theory?", "Explain τ_eff in simple terms"],
|
| 38 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
chat.launch()
|