SeaWolf-AI commited on
Commit
332174b
Β·
verified Β·
1 Parent(s): 331fd14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -40
app.py CHANGED
@@ -33,31 +33,14 @@ SGLANG_BASE = os.getenv("DARWIN_API", "http://localhost:7947")
33
  SGLANG_URL = f"{SGLANG_BASE}/v1/chat/completions"
34
 
35
  # Multi-model config
36
- MODELS = {
37
- "Darwin-35B-A3B-Opus": {
38
- "id": "FINAL-Bench/Darwin-35B-A3B-Opus",
39
- "api": os.getenv("DARWIN_API", "http://localhost:7947"),
40
- "arch": "MoE", "active": "3B / 35B total",
41
- "ctx": "262K", "thinking": True, "vision": True,
42
- "max_tokens": 16384, "temp_max": 1.5,
43
- "desc": "Original BF16 Β· SGLang",
44
- "badge": "BF16",
45
- },
46
- "Darwin-35B-A3B-Opus-Q8-GGUF": {
47
- "id": "FINAL-Bench/Darwin-35B-A3B-Opus-Q8-GGUF",
48
- "api": os.getenv("DARWIN_GGUF_API", "http://localhost:8080"),
49
- "arch": "MoE", "active": "3B / 35B total",
50
- "ctx": "262K", "thinking": True, "vision": False,
51
- "max_tokens": 16384, "temp_max": 1.5,
52
- "desc": "Q8_0 GGUF Β· llama.cpp",
53
- "badge": "Q8 GGUF",
54
- },
55
  }
56
 
57
- DEFAULT_MODEL = "Darwin-35B-A3B-Opus"
58
- MODEL_NAME = DEFAULT_MODEL
59
- MODEL_CAP = MODELS[DEFAULT_MODEL]
60
-
61
  PRESETS = {
62
  "general": "You are Darwin-35B-A3B-Opus, a highly capable reasoning model created by VIDRAFT via evolutionary merge. Think step by step for complex questions.",
63
  "code": "You are an expert software engineer. Write clean, efficient, well-commented code. Explain your approach before writing. Use modern best practices.",
@@ -174,14 +157,12 @@ def generate_reply(
174
  max_new_tokens: int,
175
  temperature: float,
176
  top_p: float,
177
- model_name: str = "Darwin-35B-A3B-Opus",
178
  ) -> Generator[str, None, None]:
179
 
180
- mcfg = MODELS.get(model_name, MODELS[DEFAULT_MODEL])
181
- api_url = f"{mcfg['api']}/v1/chat/completions"
182
  use_think = "Thinking" in thinking_mode
183
- max_new_tokens = min(int(max_new_tokens), mcfg["max_tokens"])
184
- temperature = min(float(temperature), mcfg["temp_max"])
185
 
186
  messages: list[dict] = []
187
  if system_prompt.strip():
@@ -218,7 +199,7 @@ def generate_reply(
218
  user_text = build_user_message(message, use_think)
219
 
220
  # Vision: image input handling
221
- if image_input and mcfg["vision"]:
222
  import io
223
  from PIL import Image as PILImage
224
 
@@ -247,7 +228,7 @@ def generate_reply(
247
  api_urls.append(f"{H100_API.rstrip('/')}/v1/chat/completions")
248
 
249
  request_body = {
250
- "model": mcfg["id"],
251
  "messages": messages,
252
  "max_tokens": max_new_tokens,
253
  "temperature": temperature,
@@ -327,7 +308,6 @@ with gr.Blocks(title="Darwin-35B-A3B-Opus") as gradio_demo:
327
  max_new_tokens = gr.Slider(minimum=64, maximum=16384, value=4096, visible=False)
328
  temperature = gr.Slider(minimum=0.0, maximum=1.5, value=0.6, visible=False)
329
  top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, visible=False)
330
- model_selector = gr.Textbox(value=DEFAULT_MODEL, visible=False)
331
 
332
  gr.ChatInterface(
333
  fn=generate_reply,
@@ -335,7 +315,6 @@ with gr.Blocks(title="Darwin-35B-A3B-Opus") as gradio_demo:
335
  additional_inputs=[
336
  thinking_toggle, image_input,
337
  system_prompt, max_new_tokens, temperature, top_p,
338
- model_selector,
339
  ],
340
  )
341
 
@@ -433,14 +412,6 @@ async def health():
433
  except:
434
  return {"status":"ok","sglang":"disconnected"}
435
 
436
- @fapp.get("/api/models")
437
- async def api_models():
438
- return JSONResponse({
439
- "models": {k: {"desc": v["desc"], "badge": v["badge"], "vision": v["vision"], "ctx": v["ctx"]}
440
- for k, v in MODELS.items()},
441
- "default": DEFAULT_MODEL,
442
- })
443
-
444
  # ── Web Search API (Brave) ──────────────────────────────────────────────
445
  BRAVE_API_KEY = os.getenv("BRAVE_API_KEY", "")
446
 
 
33
  SGLANG_URL = f"{SGLANG_BASE}/v1/chat/completions"
34
 
35
  # Multi-model config
36
+ MODEL_NAME = "Darwin-35B-A3B-Opus"
37
+ MODEL_ID = "FINAL-Bench/Darwin-35B-A3B-Opus"
38
+ MODEL_CAP = {
39
+ "arch": "MoE", "active": "3B / 35B total",
40
+ "ctx": "262K", "thinking": True, "vision": True,
41
+ "max_tokens": 16384, "temp_max": 1.5,
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  }
43
 
 
 
 
 
44
  PRESETS = {
45
  "general": "You are Darwin-35B-A3B-Opus, a highly capable reasoning model created by VIDRAFT via evolutionary merge. Think step by step for complex questions.",
46
  "code": "You are an expert software engineer. Write clean, efficient, well-commented code. Explain your approach before writing. Use modern best practices.",
 
157
  max_new_tokens: int,
158
  temperature: float,
159
  top_p: float,
 
160
  ) -> Generator[str, None, None]:
161
 
162
+ api_url = f"{SGLANG_BASE}/v1/chat/completions"
 
163
  use_think = "Thinking" in thinking_mode
164
+ max_new_tokens = min(int(max_new_tokens), MODEL_CAP["max_tokens"])
165
+ temperature = min(float(temperature), MODEL_CAP["temp_max"])
166
 
167
  messages: list[dict] = []
168
  if system_prompt.strip():
 
199
  user_text = build_user_message(message, use_think)
200
 
201
  # Vision: image input handling
202
+ if image_input and MODEL_CAP["vision"]:
203
  import io
204
  from PIL import Image as PILImage
205
 
 
228
  api_urls.append(f"{H100_API.rstrip('/')}/v1/chat/completions")
229
 
230
  request_body = {
231
+ "model": MODEL_ID,
232
  "messages": messages,
233
  "max_tokens": max_new_tokens,
234
  "temperature": temperature,
 
308
  max_new_tokens = gr.Slider(minimum=64, maximum=16384, value=4096, visible=False)
309
  temperature = gr.Slider(minimum=0.0, maximum=1.5, value=0.6, visible=False)
310
  top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, visible=False)
 
311
 
312
  gr.ChatInterface(
313
  fn=generate_reply,
 
315
  additional_inputs=[
316
  thinking_toggle, image_input,
317
  system_prompt, max_new_tokens, temperature, top_p,
 
318
  ],
319
  )
320
 
 
412
  except:
413
  return {"status":"ok","sglang":"disconnected"}
414
 
 
 
 
 
 
 
 
 
415
  # ── Web Search API (Brave) ──────────────────────────────────────────────
416
  BRAVE_API_KEY = os.getenv("BRAVE_API_KEY", "")
417