File size: 2,342 Bytes
ecbbaac
697b71b
2cca466
ecbbaac
2c5e1cd
697b71b
30655bb
 
 
2c5e1cd
2cca466
 
 
2c5e1cd
 
 
 
 
 
 
 
 
 
 
 
 
2cca466
 
30655bb
697b71b
 
 
2cca466
 
697b71b
2c5e1cd
697b71b
2cca466
697b71b
 
 
2c5e1cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Use light model for fast inference
model_name = "Salesforce/codet5-small"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

# Auto-detect device
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)

# Supported languages and file extensions
language_prompts = {
    "Python": "Fix the following Python code and provide the corrected version:",
    "C": "Fix the following C code and provide the corrected version:",
    "C++": "Fix the following C++ code and provide the corrected version:",
    "JavaScript": "Fix the following JavaScript code and provide the corrected version:"
}

def eternos_debugger(code, error, language):
    if not code.strip() or not language.strip():
        return "❌ Please enter code and select a language."

    prompt = f"{language_prompts[language]}\n{code}\nError:\n{error}\nCorrected Code:"

    inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512).to(device)

    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_length=128,
            num_beams=2,
            early_stopping=True,
            temperature=0.7
        )

    fixed_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return fixed_code.strip()

# Gradio Interface
with gr.Blocks(theme=gr.themes.Monochrome(), css="body {background-color: black !important;}") as demo:
    gr.Markdown("<h1 style='color: white;'>βš™οΈ Eternos β€” AI Code Debugger</h1>")
    gr.Markdown("<p style='color: grey;'>Fast AI-powered debugger for Python, C, C++, and JavaScript</p>")

    with gr.Row():
        code_input = gr.Textbox(label="πŸ“ Your Code", lines=15, placeholder="Paste your buggy code here...")
        error_input = gr.Textbox(label="⚠️ Error Message", lines=4, placeholder="Paste error (optional)...")

    language_input = gr.Dropdown(choices=["Python", "C", "C++", "JavaScript"], label="🌐 Language", value="Python")

    output_code = gr.Code(label="βœ… Suggested Fix")

    run_button = gr.Button("πŸ› οΈ Fix Code")

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

demo.launch()