Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,40 @@
|
|
|
|
|
| 1 |
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 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
model.to(device)
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
# Gradio UI
|
| 21 |
with gr.Blocks(css="""
|
| 22 |
#logo-container {
|
| 23 |
display: flex;
|
|
@@ -41,16 +58,20 @@ with gr.Blocks(css="""
|
|
| 41 |
}
|
| 42 |
""") as demo:
|
| 43 |
with gr.Column():
|
| 44 |
-
with gr.Row(elem_id="logo-container"):
|
| 45 |
-
gr.Image(value="763f8a67-91ed-4f76-9296-d64a30676efd.png", width=100, height=100, show_label=False, show_download_button=False)
|
| 46 |
-
gr.Markdown("<div class='title-text'> Eternos Beta β The Coder's friend</div>")
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
debug_btn.click(fn=debug_code, inputs=[code_input, language], outputs=output)
|
| 54 |
|
| 55 |
-
# Launch the app
|
| 56 |
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import torch
|
| 3 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
|
| 4 |
|
| 5 |
+
# Load StarCoder model
|
| 6 |
+
model_name = "bigcode/starcoder"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 9 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 10 |
model.to(device)
|
| 11 |
|
| 12 |
+
# Prompts per language
|
| 13 |
+
language_prompts = {
|
| 14 |
+
"Python": "### Fix Python code:\n### Buggy code:\n",
|
| 15 |
+
"C": "### Fix C code:\n### Buggy code:\n",
|
| 16 |
+
"C++": "### Fix C++ code:\n### Buggy code:\n",
|
| 17 |
+
"JavaScript": "### Fix JavaScript code:\n### Buggy code:\n"
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
# Debugging function
|
| 21 |
+
def eternos_debugger(code, error, language):
|
| 22 |
+
if not code.strip():
|
| 23 |
+
return "β Please provide code."
|
| 24 |
+
prompt = f"{language_prompts[language]}{code}\n### Error:\n{error}\n### Corrected code:\n"
|
| 25 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=8192).to(device)
|
| 26 |
+
outputs = model.generate(
|
| 27 |
+
**inputs,
|
| 28 |
+
max_new_tokens=256,
|
| 29 |
+
temperature=0.2,
|
| 30 |
+
top_p=0.95,
|
| 31 |
+
do_sample=False,
|
| 32 |
+
pad_token_id=tokenizer.eos_token_id
|
| 33 |
+
)
|
| 34 |
+
resp = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 35 |
+
return resp.strip()
|
| 36 |
|
| 37 |
+
# Gradio UI
|
| 38 |
with gr.Blocks(css="""
|
| 39 |
#logo-container {
|
| 40 |
display: flex;
|
|
|
|
| 58 |
}
|
| 59 |
""") as demo:
|
| 60 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
|
| 63 |
+
gr.Markdown("<div class='title-text'> Eternos Beta β A Coder's Friend </div>")
|
| 64 |
+
|
| 65 |
+
with gr.Row():
|
| 66 |
+
language_input = gr.Dropdown(["Python", "C", "C++", "JavaScript"], label="π Language", value="Python")
|
| 67 |
+
|
| 68 |
+
with gr.Row():
|
| 69 |
+
code_input = gr.Textbox(label="π Your Code", lines=12, placeholder="Paste or write buggy code here...")
|
| 70 |
+
error_input = gr.Textbox(label="β οΈ Error Message (optional)", lines=4, placeholder="Paste the error traceback here (optional)")
|
| 71 |
+
|
| 72 |
+
run_btn = gr.Button("π§ Fix Code")
|
| 73 |
+
output_code = gr.Code(label="β
Suggested Fix")
|
| 74 |
|
| 75 |
+
run_btn.click(fn=eternos_debugger, inputs=[code_input, error_input, language_input], outputs=output_code)
|
|
|
|
| 76 |
|
|
|
|
| 77 |
demo.launch()
|