Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,44 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from transformers import AutoTokenizer,
|
|
|
|
|
4 |
|
5 |
-
#
|
6 |
-
MODEL_NAME = "
|
7 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
8 |
-
model =
|
9 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
10 |
model.to(device)
|
11 |
|
12 |
-
|
13 |
-
LANGUAGE_PROMPTS = {
|
14 |
-
"Python": "Fix this Python code:",
|
15 |
-
"C": "Fix this C code:",
|
16 |
-
"C++": "Fix this C++ code:",
|
17 |
-
"JavaScript": "Fix this JavaScript code:"
|
18 |
-
}
|
19 |
-
|
20 |
-
def eternos_debugger(code, error, language):
|
21 |
if not code.strip():
|
22 |
-
return "β Please
|
23 |
-
|
|
|
24 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512).to(device)
|
25 |
-
outputs = model.generate(
|
26 |
-
**inputs,
|
27 |
-
max_new_tokens=256,
|
28 |
-
temperature=0.1,
|
29 |
-
top_p=0.9,
|
30 |
-
do_sample=False,
|
31 |
-
pad_token_id=tokenizer.eos_token_id
|
32 |
-
)
|
33 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
34 |
-
return response.strip()
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
gr.Markdown("Supports Python, C, C++, JavaScript β powered by CodeGemma 1.1B")
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
demo = create_interface()
|
56 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
+
from threading import Thread
|
5 |
+
import time
|
6 |
|
7 |
+
# Load small and fast model for Python code debugging
|
8 |
+
MODEL_NAME = "Salesforce/codet5-small"
|
9 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
10 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
11 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
12 |
model.to(device)
|
13 |
|
14 |
+
def debug_python(code, progress=gr.State(0)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
if not code.strip():
|
16 |
+
return "β Please enter Python code.", 0
|
17 |
+
|
18 |
+
prompt = f"Fix this Python code:\n{code}\nCorrected code:\n"
|
19 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512).to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
def update_progress():
|
22 |
+
for i in range(1, 101):
|
23 |
+
time.sleep(0.005) # Faster loading feel
|
24 |
+
progress.value = i
|
|
|
25 |
|
26 |
+
Thread(target=update_progress).start()
|
27 |
+
|
28 |
+
outputs = model.generate(**inputs, max_new_tokens=256, temperature=0.2, do_sample=False)
|
29 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
30 |
+
progress.value = 100
|
31 |
+
return response.strip(), 100
|
32 |
|
33 |
+
with gr.Blocks(css=".gradio-container {background-color: #cbedec;}") as app:
|
34 |
+
gr.Markdown("## π Python Code Debugger (Fast Mode)")
|
35 |
+
gr.Markdown("Just paste your Python code. The AI will fix any issues it detects.")
|
36 |
|
37 |
+
code_box = gr.Textbox(label="π Your Python Code", lines=12)
|
38 |
+
progress_bar = gr.Slider(minimum=0, maximum=100, value=0, interactive=False, label="β³ Progress (%)")
|
39 |
+
output = gr.Code(label="β
Suggested Fix")
|
40 |
+
fix_btn = gr.Button("π οΈ Debug Code")
|
41 |
|
42 |
+
fix_btn.click(fn=debug_python, inputs=[code_box], outputs=[output, progress_bar])
|
43 |
|
44 |
+
app.launch()
|
|
|
|