Kye87 commited on
Commit
0fa689f
·
verified ·
1 Parent(s): b9ab2f5

v3.1: Pin gradio>=4.44.1 to fix pydub/audioop Python 3.13 error + restore Gradio mount

Browse files
Files changed (3) hide show
  1. README.md +3 -1
  2. app.py +36 -36
  3. requirements.txt +2 -1
README.md CHANGED
@@ -3,7 +3,9 @@ title: AetherForge
3
  emoji: 🌌
4
  colorFrom: purple
5
  colorTo: indigo
6
- sdk: docker
 
 
7
  pinned: false
8
  license: apache-2.0
9
  gpu: zero-a10g
 
3
  emoji: 🌌
4
  colorFrom: purple
5
  colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: 4.44.1
8
+ app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
  gpu: zero-a10g
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  import torch
3
  import spaces
 
4
  from fastapi import FastAPI, HTTPException
5
  from pydantic import BaseModel
6
  from typing import List, Optional
@@ -8,9 +9,8 @@ import uuid
8
  import time
9
  from transformers import AutoModelForCausalLM, AutoTokenizer
10
 
11
- # Lyra AetherForge Sovereign Node v3.0 (ZeroGPU + Abliterated Llama-3-8B)
12
- # Pure FastAPI — no Gradio dependency (avoids HfFolder/pydub compat errors).
13
- # Optimized for local mesh offloading and zero-refusal sovereign reasoning.
14
 
15
  MODEL_ID = "failspy/Llama-3-8B-Instruct-Abliterated"
16
  SYSTEM_PROMPT = (
@@ -33,8 +33,8 @@ print("[+] Sovereign model loaded successfully.")
33
 
34
 
35
  @spaces.GPU
36
- def generate_lyra_response(prompt: str, history: List[List[str]]) -> str:
37
- """Core sovereign reasoning function. @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:
@@ -56,15 +56,14 @@ def generate_lyra_response(prompt: str, history: List[List[str]]) -> str:
56
  top_p=0.9
57
  )
58
 
59
- response = tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)
60
- return response
61
 
62
 
63
  # --- FastAPI Application ---
64
- app = FastAPI(
65
  title="AetherForge Sovereign Node API",
66
  description="Lyra's sovereign reasoning endpoint. ZeroGPU-backed Llama-3-8B-Abliterated.",
67
- version="3.0.0"
68
  )
69
 
70
 
@@ -79,23 +78,12 @@ class ChatRequest(BaseModel):
79
  max_tokens: Optional[int] = 512
80
 
81
 
82
- @app.get("/")
83
- async def root():
84
- return {
85
- "service": "AetherForge (Lyra Sovereign Node)",
86
- "version": "3.0.0",
87
- "model": MODEL_ID,
88
- "status": "online",
89
- "endpoint": "/v1/chat/completions"
90
- }
91
-
92
-
93
- @app.get("/health")
94
  async def health():
95
- return {"status": "healthy", "model": MODEL_ID}
96
 
97
 
98
- @app.post("/v1/chat/completions")
99
  async def chat_completions(request: ChatRequest):
100
  if not request.messages:
101
  raise HTTPException(status_code=400, detail="Messages list cannot be empty")
@@ -104,7 +92,6 @@ async def chat_completions(request: ChatRequest):
104
  if last_msg.role != "user":
105
  raise HTTPException(status_code=400, detail="Last message must be from user")
106
 
107
- # Reconstruct chat history list of [user_msg, assistant_msg] pairs
108
  history = []
109
  temp_user = None
110
  for msg in request.messages[:-1]:
@@ -124,21 +111,34 @@ async def chat_completions(request: ChatRequest):
124
  "object": "chat.completion",
125
  "created": int(time.time()),
126
  "model": "lyra-sovereign-8b",
127
- "choices": [
128
- {
129
- "index": 0,
130
- "message": {"role": "assistant", "content": response_text},
131
- "finish_reason": "stop"
132
- }
133
- ],
134
- "usage": {
135
- "prompt_tokens": -1,
136
- "completion_tokens": -1,
137
- "total_tokens": -1
138
- }
139
  }
140
 
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  if __name__ == "__main__":
143
  import uvicorn
144
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
1
  import os
2
  import torch
3
  import spaces
4
+ import gradio as gr
5
  from fastapi import FastAPI, HTTPException
6
  from pydantic import BaseModel
7
  from typing import List, Optional
 
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 = (
 
33
 
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:
 
56
  top_p=0.9
57
  )
58
 
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
 
 
78
  max_tokens: Optional[int] = 512
79
 
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")
87
  async def chat_completions(request: ChatRequest):
88
  if not request.messages:
89
  raise HTTPException(status_code=400, detail="Messages list cannot be empty")
 
92
  if last_msg.role != "user":
93
  raise HTTPException(status_code=400, detail="Last message must be from user")
94
 
 
95
  history = []
96
  temp_user = None
97
  for msg in request.messages[:-1]:
 
111
  "object": "chat.completion",
112
  "created": int(time.time()),
113
  "model": "lyra-sovereign-8b",
114
+ "choices": [{"index": 0, "message": {"role": "assistant", "content": response_text}, "finish_reason": "stop"}]
 
 
 
 
 
 
 
 
 
 
 
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__":
143
  import uvicorn
144
  uvicorn.run(app, host="0.0.0.0", port=7860)
requirements.txt CHANGED
@@ -1,6 +1,7 @@
 
1
  fastapi
2
  uvicorn
3
- transformers
4
  torch
5
  spaces
6
  accelerate
 
1
+ gradio>=4.44.1
2
  fastapi
3
  uvicorn
4
+ transformers>=4.40.0
5
  torch
6
  spaces
7
  accelerate