Regraph commited on
Commit
b2c117a
·
verified ·
1 Parent(s): e634ca4

Deploy ReGraph LLM Gradio demo via ReGraph platform

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -1,17 +1,19 @@
1
  import gradio as gr
2
  import requests
3
  import os
 
4
 
5
  REGRAPH_API_KEY = os.getenv("REGRAPH_API_KEY", "")
6
  REGRAPH_BASE_URL = "https://api.regraph.tech/v1"
7
 
8
- def chat(message: str, history: list) -> str:
 
9
  messages = [
10
  {"role": "system", "content": "You are a helpful AI assistant powered by ReGraph LLM — a decentralized, continuously-trained language model running on distributed GPU/NPU nodes worldwide."}
11
  ]
12
- for h in history:
13
- messages.append({"role": "user", "content": h[0]})
14
- messages.append({"role": "assistant", "content": h[1]})
15
  messages.append({"role": "user", "content": message})
16
 
17
  try:
@@ -22,12 +24,13 @@ def chat(message: str, history: list) -> str:
22
  timeout=60,
23
  )
24
  resp.raise_for_status()
25
- return resp.json()["choices"][0]["message"]["content"]
26
  except Exception as e:
27
- return f"[Error] {e}"
28
 
29
  demo = gr.ChatInterface(
30
  fn=chat,
 
31
  title="⚡ ReGraph LLM",
32
  description="""Interact with **ReGraph LLM** — a continuously-trained language model powered by decentralized GPU/NPU nodes worldwide.
33
 
@@ -39,7 +42,6 @@ demo = gr.ChatInterface(
39
  "Compare centralized vs decentralized AI inference",
40
  ],
41
  theme=gr.themes.Soft(primary_hue="violet"),
42
- chatbot=gr.Chatbot(height=480),
43
  )
44
 
45
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  import requests
3
  import os
4
+ from typing import Generator
5
 
6
  REGRAPH_API_KEY = os.getenv("REGRAPH_API_KEY", "")
7
  REGRAPH_BASE_URL = "https://api.regraph.tech/v1"
8
 
9
+ # Gradio 5: history is list[dict] with keys "role" and "content"
10
+ def chat(message: str, history: list[dict]) -> Generator[str, None, None]:
11
  messages = [
12
  {"role": "system", "content": "You are a helpful AI assistant powered by ReGraph LLM — a decentralized, continuously-trained language model running on distributed GPU/NPU nodes worldwide."}
13
  ]
14
+ # Gradio 5 passes history as list of {"role": ..., "content": ...} dicts
15
+ for msg in history:
16
+ messages.append({"role": msg["role"], "content": msg["content"]})
17
  messages.append({"role": "user", "content": message})
18
 
19
  try:
 
24
  timeout=60,
25
  )
26
  resp.raise_for_status()
27
+ yield resp.json()["choices"][0]["message"]["content"]
28
  except Exception as e:
29
+ yield f"⚠️ {e}"
30
 
31
  demo = gr.ChatInterface(
32
  fn=chat,
33
+ type="messages",
34
  title="⚡ ReGraph LLM",
35
  description="""Interact with **ReGraph LLM** — a continuously-trained language model powered by decentralized GPU/NPU nodes worldwide.
36
 
 
42
  "Compare centralized vs decentralized AI inference",
43
  ],
44
  theme=gr.themes.Soft(primary_hue="violet"),
 
45
  )
46
 
47
  if __name__ == "__main__":