RFTSystems commited on
Commit
20ef4dc
·
verified ·
1 Parent(s): 2a26ecc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -51
app.py CHANGED
@@ -1,62 +1,41 @@
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()
 
 
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()