File size: 2,033 Bytes
ace22c9
697b71b
7235cb4
ecbbaac
257e31a
7235cb4
 
 
ace22c9
193e324
2c5e1cd
257e31a
ace22c9
7235cb4
 
 
 
ace22c9
 
257e31a
ace22c9
 
7235cb4
 
257e31a
7235cb4
 
 
 
 
 
 
 
 
 
 
 
 
257e31a
 
 
7235cb4
 
 
 
 
 
 
 
 
 
3ee3486
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Load CodeT5+ model and tokenizer
model_id = "Salesforce/codet5p-770m"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id, torch_dtype=torch.float32)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)

# Prompt templates for supported languages
language_prompts = {
    "Python": "Fix the following Python code:\n",
    "C": "Fix the following C code:\n",
    "C++": "Fix the following C++ code:\n",
    "JavaScript": "Fix the following JavaScript code:\n"
}

# Debug function
def eternos_debugger(code, error, language):
    if not code.strip():
        return "❌ Please enter some code to debug."
    prompt = language_prompts[language] + code + "\nError:\n" + error + "\nFixed Code:\n"

    inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512).to(device)
    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=256,
            temperature=0.3,
            top_p=0.9,
            do_sample=True
        )
    result = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return result.strip()

# Gradio Interface
with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("## πŸ› οΈ Eternos β€” AI Code Debugger")
    gr.Markdown("Supports Python, C, C++, JavaScript β€” Powered by CodeT5+")

    with gr.Row():
        code_input = gr.Textbox(label="πŸ‘¨β€πŸ’» Your Code", lines=14, placeholder="Paste your buggy code here...")
        error_input = gr.Textbox(label="⚠️ Error Message (optional)", lines=4)

    language_input = gr.Dropdown(["Python", "C", "C++", "JavaScript"], label="🌐 Language", value="Python")
    output_code = gr.Code(label="βœ… Suggested Fix")
    run_btn = gr.Button("πŸ” Debug Code")

    run_btn.click(fn=eternos_debugger, inputs=[code_input, error_input, language_input], outputs=output_code)

demo.launch()