Tanveerooooooo commited on
Commit
193e324
·
verified ·
1 Parent(s): fb70727

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -17
app.py CHANGED
@@ -2,22 +2,30 @@ import torch
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import gradio as gr
4
 
5
- # Load open-source model
6
- model_name = "replit/code-v1-3b" # Can switch to deepseek-ai/deepseek-coder-1.3b-instruct
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
- model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
9
- model.to("cuda" if torch.cuda.is_available() else "cpu")
 
10
 
11
- # Inference function
12
- def debug_code(code):
13
- prompt = f"### Fix the following code and explain:\n{code}\n### Fixed Code:"
14
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
15
- outputs = model.generate(**inputs, max_new_tokens=256, pad_token_id=tokenizer.eos_token_id)
16
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
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()