Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,44 @@
|
|
| 1 |
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
-
from transformers import
|
| 5 |
|
| 6 |
-
# 1. Configuration
|
| 7 |
model_id = "erdemozkan/YOLO-7B-Qwen-Coder"
|
| 8 |
|
| 9 |
-
print(f"🚀
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
model =
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
#
|
| 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.
|
| 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 |
-
#
|
| 53 |
-
|
| 54 |
.gradio-container { background-color: #000 !important; }
|
| 55 |
-
#
|
| 56 |
-
.code-
|
| 57 |
-
#yolo-btn { background: #ffff00 !important; color: #000 !important; font-weight: 900 !important;
|
| 58 |
-
footer { display: none !important; }
|
| 59 |
"""
|
| 60 |
|
| 61 |
-
with gr.Blocks(css=
|
| 62 |
-
|
| 63 |
-
gr.Markdown("# YOLO CODER")
|
| 64 |
-
|
| 65 |
with gr.Row():
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 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()
|