erdemozkan commited on
Commit
8d97932
·
verified ·
1 Parent(s): 5723430

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -36
app.py CHANGED
@@ -1,35 +1,44 @@
1
  import spaces
2
  import gradio as gr
3
  import torch
4
- from transformers import AutoModelForCausalLM, AutoTokenizer
5
 
6
- # 1. Configuration & Model Loading
7
  model_id = "erdemozkan/YOLO-7B-Qwen-Coder"
8
 
9
- print(f"🚀 Initializing YOLO CODER: {model_id}")
10
 
11
- # FIX: Set use_fast=False and trust_remote_code=True
12
- tokenizer = AutoTokenizer.from_pretrained(
13
- model_id,
14
- trust_remote_code=True,
15
- use_fast=False # <--- THIS BYPASSES THE ERROR
16
- )
 
 
17
 
18
- model = AutoModelForCausalLM.from_pretrained(
19
- model_id,
20
- torch_dtype=torch.bfloat16,
21
- device_map="auto",
22
- trust_remote_code=True
23
- )
 
 
 
 
 
 
 
24
 
25
- # 2. The Core Logic
26
  @spaces.GPU(duration=60)
27
  def yoco_heal(broken_code):
28
  if not broken_code or not broken_code.strip():
29
- return "⚠️ YOLO needs code. Paste something!"
30
 
31
  prompt = (
32
- "### System: You are YOLO CODER. An elite autonomous agent.\n"
33
  f"### Broken Code:\n{broken_code}\n"
34
  "### Fixed Code (No talk, just code):"
35
  )
@@ -42,34 +51,28 @@ def yoco_heal(broken_code):
42
  max_new_tokens=1024,
43
  temperature=0.2,
44
  do_sample=True,
45
- pad_token_id=tokenizer.eos_token_id
46
  )
47
 
48
  full_response = tokenizer.decode(outputs[0], skip_special_tokens=True)
49
  marker = "### Fixed Code (No talk, just code):"
50
  return full_response.split(marker)[1].strip() if marker in full_response else full_response
51
 
52
- # 3. UI and CSS
53
- css_hack = """
54
  .gradio-container { background-color: #000 !important; }
55
- #yoco-header h1 { color: #ffff00 !important; text-shadow: 0 0 10px #ffff00; text-align: center; }
56
- .code-container { border: 1px solid #ffff00 !important; background: #09090b !important; }
57
- #yolo-btn { background: #ffff00 !important; color: #000 !important; font-weight: 900 !important; box-shadow: 0 0 15px #ffff00; }
58
- footer { display: none !important; }
59
  """
60
 
61
- with gr.Blocks(css=css_hack) as demo:
62
- with gr.Column(elem_id="yoco-header"):
63
- gr.Markdown("# YOLO CODER")
64
-
65
  with gr.Row():
66
- with gr.Column():
67
- input_box = gr.Code(label="INPUT", language="python", lines=15, elem_classes="code-container")
68
- heal_btn = gr.Button("YOLO IT!", elem_id="yolo-btn")
69
- with gr.Column():
70
- output_box = gr.Code(label="HEALED", language="python", lines=15, elem_classes="code-container", interactive=False)
71
-
72
- heal_btn.click(fn=yoco_heal, inputs=input_box, outputs=output_box)
73
 
74
  if __name__ == "__main__":
75
  demo.launch()
 
1
  import spaces
2
  import gradio as gr
3
  import torch
4
+ from transformers import Qwen2ForCausalLM, Qwen2Tokenizer, Qwen2Config
5
 
6
+ # 1. Configuration
7
  model_id = "erdemozkan/YOLO-7B-Qwen-Coder"
8
 
9
+ print(f"🚀 YOLO CODER: Forcing Qwen2 Engine for {model_id}...")
10
 
11
+ # 2. Direct Loading (Bypassing AutoModel/AutoTokenizer)
12
+ # We use the specific Qwen2 classes to avoid the 'Unrecognized' error
13
+ try:
14
+ tokenizer = Qwen2Tokenizer.from_pretrained(
15
+ model_id,
16
+ trust_remote_code=True,
17
+ use_fast=False # Standard Python backend is more stable for custom weights
18
+ )
19
 
20
+ model = Qwen2ForCausalLM.from_pretrained(
21
+ model_id,
22
+ torch_dtype=torch.bfloat16,
23
+ device_map="auto",
24
+ trust_remote_code=True
25
+ )
26
+ except Exception as e:
27
+ print(f"❌ Direct load failed: {e}")
28
+ print("Falling back to Auto-classes with forced config...")
29
+ # Last ditch effort if Qwen2 classes aren't in the path
30
+ from transformers import AutoModelForCausalLM, AutoTokenizer
31
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
32
+ model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True, device_map="auto")
33
 
34
+ # 3. The Core Logic
35
  @spaces.GPU(duration=60)
36
  def yoco_heal(broken_code):
37
  if not broken_code or not broken_code.strip():
38
+ return "⚠️ YOLO needs code."
39
 
40
  prompt = (
41
+ "### System: You are YOLO CODER (yoco). An elite autonomous agent.\n"
42
  f"### Broken Code:\n{broken_code}\n"
43
  "### Fixed Code (No talk, just code):"
44
  )
 
51
  max_new_tokens=1024,
52
  temperature=0.2,
53
  do_sample=True,
54
+ pad_token_id=tokenizer.eos_token_id if tokenizer.eos_token_id else 151643
55
  )
56
 
57
  full_response = tokenizer.decode(outputs[0], skip_special_tokens=True)
58
  marker = "### Fixed Code (No talk, just code):"
59
  return full_response.split(marker)[1].strip() if marker in full_response else full_response
60
 
61
+ # 4. Neon-Hacker UI
62
+ css = """
63
  .gradio-container { background-color: #000 !important; }
64
+ #header h1 { color: #ffff00 !important; text-shadow: 0 0 10px #ffff00; text-align: center; }
65
+ .code-box { border: 1px solid #ffff00 !important; background: #09090b !important; }
66
+ #yolo-btn { background: #ffff00 !important; color: #000 !important; font-weight: 900 !important; }
 
67
  """
68
 
69
+ with gr.Blocks(css=css) as demo:
70
+ gr.Markdown("# YOLO CODER", elem_id="header")
 
 
71
  with gr.Row():
72
+ in_code = gr.Code(label="INPUT", language="python", lines=15, elem_classes="code-box")
73
+ out_code = gr.Code(label="HEALED", language="python", lines=15, elem_classes="code-box", interactive=False)
74
+ btn = gr.Button("YOLO IT!", elem_id="yolo-btn")
75
+ btn.click(yoco_heal, in_code, out_code)
 
 
 
76
 
77
  if __name__ == "__main__":
78
  demo.launch()