arthpandeyofficial commited on
Commit
0222a81
路
verified 路
1 Parent(s): 9afb839

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -51,18 +51,18 @@ logging.getLogger("httpcore").setLevel(logging.WARNING)
51
  HF_TOKEN = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
52
  os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "1")
53
 
54
- # Instruction-tuned Gemma, Qwen Coder, and R1 Distill 14B
55
  MODELS = {
56
  "Chat": "google/gemma-4-31B-it",
57
- "Code": "Qwen/Qwen2.5-Coder-32B-Instruct",
58
  "Think": "deepseek-ai/DeepSeek-R1-Distill-Qwen-14B",
59
  }
60
 
61
- # Generous ZeroGPU budgets so inference completes without server aborts
62
  GPU_BUDGETS = {
63
- "guest": {"Chat": 60, "Code": 55, "Think": 60},
64
- "free": {"Chat": 75, "Code": 70, "Think": 75},
65
- "pro": {"Chat": 100, "Code": 90, "Think": 120},
66
  }
67
 
68
  THINK_OPEN = re.compile(r"<think>|鈼乼hink鈻穦<\|think\|>", re.I)
@@ -264,12 +264,12 @@ def history_to_prompt(history: list, mode: str, tokenizer) -> str:
264
  messages = [
265
  {
266
  "role": "system",
267
- "content": "Write correct, complete code. Prefer a working snippet over an essay.",
268
  },
269
  *visible,
270
  ]
271
  else:
272
- # Chat: plain messages with no added system instructions or branding changes
273
  messages = visible
274
 
275
  if tokenizer.chat_template and messages:
@@ -383,7 +383,7 @@ def generate_response(
383
  streamer=streamer,
384
  max_new_tokens=max_new,
385
  do_sample=True,
386
- temperature=0.6 if mode == "Think" else 0.4,
387
  top_p=0.9,
388
  repetition_penalty=1.12,
389
  pad_token_id=tokenizer.pad_token_id,
@@ -393,7 +393,8 @@ def generate_response(
393
  worker.start()
394
 
395
  raw = ""
396
- deadline = time.monotonic() + max(8, seconds - 4)
 
397
  try:
398
  for chunk in streamer:
399
  raw += chunk
@@ -422,7 +423,6 @@ def handle_user_submission(message, history):
422
  raise gr.Error("Enter a message first.")
423
  new_history = copy.deepcopy(history or [])
424
  new_history.append({"role": "user", "content": message})
425
- # Instantly clear textbox and lock controls to avoid multiple clicks
426
  off = gr.update(interactive=False)
427
  return "", new_history, off, off, off
428
 
@@ -498,7 +498,7 @@ with gr.Blocks(
498
  choices=["Chat", "Code", "Think"],
499
  value="Chat",
500
  label="Mode",
501
- info="Chat = Gemma 4 31B IT 路 Code = Qwen2.5-Coder-32B 路 Think = R1-Distill-Qwen-14B",
502
  )
503
  chatbot = gr.Chatbot(
504
  label="Chat",
 
51
  HF_TOKEN = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
52
  os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "1")
53
 
54
+ # Switched Code to NextCoder-14B for faster loading & lower VRAM overhead
55
  MODELS = {
56
  "Chat": "google/gemma-4-31B-it",
57
+ "Code": "microsoft/NextCoder-14B",
58
  "Think": "deepseek-ai/DeepSeek-R1-Distill-Qwen-14B",
59
  }
60
 
61
+ # PRO tier gets the full 180s ceiling; Guest and Free tiers get standard allotments
62
  GPU_BUDGETS = {
63
+ "guest": {"Chat": 45, "Code": 50, "Think": 50},
64
+ "free": {"Chat": 60, "Code": 70, "Think": 70},
65
+ "pro": {"Chat": 120, "Code": 180, "Think": 180},
66
  }
67
 
68
  THINK_OPEN = re.compile(r"<think>|鈼乼hink鈻穦<\|think\|>", re.I)
 
264
  messages = [
265
  {
266
  "role": "system",
267
+ "content": "Write correct, clean, complete code. Prefer a working snippet over an essay.",
268
  },
269
  *visible,
270
  ]
271
  else:
272
+ # Chat: plain messages, pure natural responses with no added system instructions
273
  messages = visible
274
 
275
  if tokenizer.chat_template and messages:
 
383
  streamer=streamer,
384
  max_new_tokens=max_new,
385
  do_sample=True,
386
+ temperature=0.6 if mode == "Think" else 0.3,
387
  top_p=0.9,
388
  repetition_penalty=1.12,
389
  pad_token_id=tokenizer.pad_token_id,
 
393
  worker.start()
394
 
395
  raw = ""
396
+ # Safe internal cutoff: 5 seconds before the ZeroGPU allocation expires
397
+ deadline = time.monotonic() + max(8, seconds - 5)
398
  try:
399
  for chunk in streamer:
400
  raw += chunk
 
423
  raise gr.Error("Enter a message first.")
424
  new_history = copy.deepcopy(history or [])
425
  new_history.append({"role": "user", "content": message})
 
426
  off = gr.update(interactive=False)
427
  return "", new_history, off, off, off
428
 
 
498
  choices=["Chat", "Code", "Think"],
499
  value="Chat",
500
  label="Mode",
501
+ info="Chat = Gemma 4 31B IT 路 Code = NextCoder-14B 路 Think = R1-Distill-Qwen-14B",
502
  )
503
  chatbot = gr.Chatbot(
504
  label="Chat",