erdemozkan commited on
Commit
61c2fdb
·
verified ·
1 Parent(s): f51382e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ import torch
4
+ from transformers import AutoModelForCausalLM, AutoTokenizer
5
+
6
+ # 1. Load your model at the root level (required for ZeroGPU)
7
+ model_id = "erdemozkan/YOLO-7B-Qwen-Coder"
8
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
9
+ model = AutoModelForCausalLM.from_pretrained(
10
+ model_id,
11
+ torch_dtype=torch.bfloat16,
12
+ device_map="auto"
13
+ )
14
+
15
+ # 2. The GPU-decorated function
16
+ @spaces.GPU(duration=60) # Declares a 60s window on the H200
17
+ def yoco_heal(broken_code):
18
+ prompt = f"### System: You are YOLO CODER. Analyze the following broken code and provide a self-healed, working version.\n\n### Broken Code:\n{broken_code}\n\n### Fixed Code:"
19
+
20
+ inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
21
+
22
+ with torch.no_grad():
23
+ outputs = model.generate(
24
+ **inputs,
25
+ max_new_tokens=1024,
26
+ temperature=0.7,
27
+ do_sample=True
28
+ )
29
+
30
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
31
+ # Extract only the code part from the response
32
+ if "### Fixed Code:" in response:
33
+ return response.split("### Fixed Code:")[1].strip()
34
+ return response
35
+
36
+ # 3. The "YOLO" Themed UI
37
+ yoco_theme = gr.themes.Soft(
38
+ primary_hue="yellow",
39
+ secondary_hue="zinc",
40
+ neutral_hue="slate",
41
+ ).set(
42
+ body_background_fill="#09090b", # Dark OLED black
43
+ block_background_fill="#18181b",
44
+ button_primary_background_fill="*primary_500",
45
+ button_primary_text_color="black",
46
+ )
47
+
48
+ with gr.Blocks(theme=yoco_theme) as demo:
49
+ gr.Markdown("# 🚀 YOLO CODER: Self-Healing AI")
50
+ gr.Markdown("Drop your broken code. Let **yoco** fix it while you grab a coffee.")
51
+
52
+ with gr.Row():
53
+ with gr.Column():
54
+ input_code = gr.Code(label="Paste Broken Code", language="python", lines=15)
55
+ heal_btn = gr.Button("YOLO IT!", variant="primary")
56
+ with gr.Column():
57
+ output_code = gr.Code(label="Self-Healed Output", language="python", lines=15)
58
+
59
+ heal_btn.click(fn=yoco_heal, inputs=input_code, outputs=output_code)
60
+
61
+ gr.Markdown("---")
62
+ gr.Markdown("Built by [Erdem Ozkan](https://huggingface.co/erdemozkan) | Powered by Qwen 7B & ZeroGPU")
63
+
64
+ demo.launch()