lakshraina2 commited on
Commit
9b5884f
·
verified ·
1 Parent(s): 507568d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -2,20 +2,23 @@ import gradio as gr
2
  import torch
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
 
5
- # Replace with your actual merged model repo
6
- model_id = "lakshraina2/leetcode-coder-1.5B"
7
 
8
- print("Loading model on CPU...")
9
- tokenizer = AutoTokenizer.from_pretrained(model_id)
 
 
10
  model = AutoModelForCausalLM.from_pretrained(
11
  model_id,
12
- torch_dtype=torch.float32, # CPU needs float32
13
- device_map={"": "cpu"} # Force CPU
 
14
  )
15
 
16
  def solve(problem_text):
17
  prompt = f"### Instruction:\nSolve this LeetCode problem:\n{problem_text}\n\n### Response:\n"
18
- inputs = tokenizer(prompt, return_tensors="pt") # No .to("cuda")!
19
 
20
  with torch.no_grad():
21
  outputs = model.generate(
@@ -28,6 +31,5 @@ def solve(problem_text):
28
  solution = tokenizer.decode(outputs[0], skip_special_tokens=True)
29
  return solution.split("### Response:\n")[-1].strip()
30
 
31
- # Gradio 4 interface
32
  iface = gr.Interface(fn=solve, inputs="text", outputs="text")
33
  iface.launch()
 
2
  import torch
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
 
5
+ # The public model ID
6
+ model_id = "lakshraina2/leetcodeAI"
7
 
8
+ print("Loading model on CPU (Public Access)...")
9
+
10
+ # Force token=False to bypass the 401 error on public repos
11
+ tokenizer = AutoTokenizer.from_pretrained(model_id, token=False)
12
  model = AutoModelForCausalLM.from_pretrained(
13
  model_id,
14
+ torch_dtype=torch.float32,
15
+ device_map={"": "cpu"},
16
+ token=False # This is the magic fix
17
  )
18
 
19
  def solve(problem_text):
20
  prompt = f"### Instruction:\nSolve this LeetCode problem:\n{problem_text}\n\n### Response:\n"
21
+ inputs = tokenizer(prompt, return_tensors="pt")
22
 
23
  with torch.no_grad():
24
  outputs = model.generate(
 
31
  solution = tokenizer.decode(outputs[0], skip_special_tokens=True)
32
  return solution.split("### Response:\n")[-1].strip()
33
 
 
34
  iface = gr.Interface(fn=solve, inputs="text", outputs="text")
35
  iface.launch()