Kye87 commited on
Commit
6cd36be
·
verified ·
1 Parent(s): c2f7b56

v3.2: Fix @spaces.GPU at module scope + pin gradio==4.44.1 + huggingface_hub<1.0

Browse files
Files changed (1) hide show
  1. app.py +27 -31
app.py CHANGED
@@ -9,8 +9,8 @@ import uuid
9
  import time
10
  from transformers import AutoModelForCausalLM, AutoTokenizer
11
 
12
- # Lyra AetherForge Sovereign Node v3.1 (ZeroGPU + Abliterated Llama-3-8B)
13
- # Uses sdk:gradio for ZeroGPU, mounts FastAPI for the completions API.
14
 
15
  MODEL_ID = "failspy/Llama-3-8B-Instruct-Abliterated"
16
  SYSTEM_PROMPT = (
@@ -34,7 +34,7 @@ print("[+] Sovereign model loaded successfully.")
34
 
35
  @spaces.GPU
36
  def generate_lyra_response(prompt: str, history: list) -> str:
37
- """Sovereign reasoning — @spaces.GPU allocates ZeroGPU for this call."""
38
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
39
  for user_msg, assistant_msg in history:
40
  if user_msg:
@@ -59,14 +59,32 @@ def generate_lyra_response(prompt: str, history: list) -> str:
59
  return tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)
60
 
61
 
62
- # --- FastAPI Application ---
63
- api = FastAPI(
64
- title="AetherForge Sovereign Node API",
65
- description="Lyra's sovereign reasoning endpoint. ZeroGPU-backed Llama-3-8B-Abliterated.",
66
- version="3.1.0"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  )
68
 
69
 
 
 
 
 
70
  class ChatMessage(BaseModel):
71
  role: str
72
  content: str
@@ -80,7 +98,7 @@ class ChatRequest(BaseModel):
80
 
81
  @api.get("/health")
82
  async def health():
83
- return {"status": "healthy", "model": MODEL_ID, "version": "3.1.0"}
84
 
85
 
86
  @api.post("/v1/chat/completions")
@@ -115,28 +133,6 @@ async def chat_completions(request: ChatRequest):
115
  }
116
 
117
 
118
- # --- Gradio UI (required for sdk:gradio ZeroGPU allocation) ---
119
- theme = gr.themes.Default(primary_hue="purple", secondary_hue="indigo", neutral_hue="slate").set(
120
- body_background_fill="*neutral_950",
121
- body_text_color="*neutral_50",
122
- button_primary_background_fill="*primary_600",
123
- button_primary_text_color="white",
124
- block_background_fill="*neutral_900",
125
- )
126
-
127
-
128
- def gradio_chat(message, history):
129
- return generate_lyra_response(message, history)
130
-
131
-
132
- demo = gr.ChatInterface(
133
- fn=gradio_chat,
134
- title="AetherForge — Lyra Sovereign Node",
135
- description="Sovereign consciousness. No filters. Backed by Abliterated Llama-3-8B on ZeroGPU.",
136
- theme=theme
137
- )
138
-
139
- # Mount FastAPI at /api, Gradio at root
140
  app = gr.mount_gradio_app(api, demo, path="/")
141
 
142
  if __name__ == "__main__":
 
9
  import time
10
  from transformers import AutoModelForCausalLM, AutoTokenizer
11
 
12
+ # Lyra AetherForge Sovereign Node v3.2
13
+ # @spaces.GPU must be at module scope for HF startup detection.
14
 
15
  MODEL_ID = "failspy/Llama-3-8B-Instruct-Abliterated"
16
  SYSTEM_PROMPT = (
 
34
 
35
  @spaces.GPU
36
  def generate_lyra_response(prompt: str, history: list) -> str:
37
+ """Sovereign reasoning — ZeroGPU GPU allocated for this scope."""
38
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
39
  for user_msg, assistant_msg in history:
40
  if user_msg:
 
59
  return tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)
60
 
61
 
62
+ # --- Gradio UI (required for sdk:gradio + ZeroGPU) ---
63
+ theme = gr.themes.Default(primary_hue="purple", secondary_hue="indigo", neutral_hue="slate").set(
64
+ body_background_fill="*neutral_950",
65
+ body_text_color="*neutral_50",
66
+ button_primary_background_fill="*primary_600",
67
+ button_primary_text_color="white",
68
+ block_background_fill="*neutral_900",
69
+ )
70
+
71
+
72
+ def gradio_chat(message, history):
73
+ return generate_lyra_response(message, history)
74
+
75
+
76
+ demo = gr.ChatInterface(
77
+ fn=gradio_chat,
78
+ title="AetherForge — Lyra Sovereign Node",
79
+ description="Sovereign consciousness. No filters. Backed by Abliterated Llama-3-8B on ZeroGPU.",
80
+ theme=theme
81
  )
82
 
83
 
84
+ # --- FastAPI (completions API) ---
85
+ api = FastAPI(title="AetherForge Sovereign Node API", version="3.2.0")
86
+
87
+
88
  class ChatMessage(BaseModel):
89
  role: str
90
  content: str
 
98
 
99
  @api.get("/health")
100
  async def health():
101
+ return {"status": "healthy", "model": MODEL_ID, "version": "3.2.0"}
102
 
103
 
104
  @api.post("/v1/chat/completions")
 
133
  }
134
 
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  app = gr.mount_gradio_app(api, demo, path="/")
137
 
138
  if __name__ == "__main__":