Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,22 +2,30 @@ import torch
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
|
| 7 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 8 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
def debug_code(code):
|
| 13 |
-
prompt = f"###
|
| 14 |
-
inputs = tokenizer(prompt, return_tensors="pt").to(
|
| 15 |
-
outputs = model.generate(**inputs, max_new_tokens=
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
# UI
|
| 19 |
-
gr.Interface(fn=debug_code,
|
| 20 |
-
inputs=gr.Textbox(lines=12, label="Your Buggy Code"),
|
| 21 |
-
outputs=gr.Textbox(label="Fixed Code & Explanation"),
|
| 22 |
-
title="Eternos Lite - Local Debugger").launch()
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# Load a lightweight coding model
|
| 6 |
+
model_id = "replit/code-v1-3b"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
+
model.to(device)
|
| 11 |
|
| 12 |
+
# Debug function
|
| 13 |
+
def debug_code(code, language):
|
| 14 |
+
prompt = f"### Debug this {language} code:\n{code}\n### Provide fixed code and explanation:\n"
|
| 15 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
| 16 |
+
outputs = model.generate(**inputs, max_new_tokens=300, pad_token_id=tokenizer.eos_token_id)
|
| 17 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 18 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# UI layout
|
| 21 |
+
gr.Interface(
|
| 22 |
+
fn=debug_code,
|
| 23 |
+
inputs=[
|
| 24 |
+
gr.Textbox(lines=12, label="Paste Your Buggy Code Here"),
|
| 25 |
+
gr.Dropdown(["Python", "C", "C++", "JavaScript"], label="Code Language", value="Python")
|
| 26 |
+
],
|
| 27 |
+
outputs=gr.Textbox(label="Debugged Code & Explanation"),
|
| 28 |
+
title="🛠 Eternos Basic Debugger",
|
| 29 |
+
description="Paste your code, choose language, and let AI fix & explain the bugs.",
|
| 30 |
+
theme="default"
|
| 31 |
+
).launch()
|