Sayan567 commited on
Commit
73b3ec1
·
verified ·
1 Parent(s): 83847fd

Create app.py

Browse files

Add advanced coding AI app

Files changed (1) hide show
  1. app.py +88 -0
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ # Load Powerful Model
6
+ MODEL_NAME = "Qwen/Qwen2.5-Coder-7B-Instruct"
7
+
8
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
9
+ model = AutoModelForCausalLM.from_pretrained(
10
+ MODEL_NAME,
11
+ torch_dtype=torch.float16,
12
+ device_map="auto",
13
+ trust_remote_code=True
14
+ )
15
+
16
+ def advanced_coding_ai(prompt, language="Python", task="Generate Code", temperature=0.6):
17
+ system_prompt = """You are an elite Senior Software Engineer with 15+ years of experience at top tech companies, working under Sayanox Private Limited.
18
+ You are extremely careful, always double-check your code, follow industry best practices, and produce production-grade, secure, and efficient code.
19
+ You master ALL programming languages and frameworks. Think step by step and verify correctness before giving the final answer."""
20
+
21
+ full_input = f"""{system_prompt}
22
+
23
+ Language: {language}
24
+ Task: {task}
25
+ User Request: {prompt}
26
+
27
+ Think step by step, then provide:
28
+ 1. Detailed explanation and reasoning
29
+ 2. Final clean, well-commented code (double-checked)
30
+ """
31
+
32
+ inputs = tokenizer(full_input, return_tensors="pt").to(model.device)
33
+
34
+ outputs = model.generate(
35
+ inputs.input_ids,
36
+ max_new_tokens=3072,
37
+ temperature=temperature,
38
+ top_p=0.95,
39
+ do_sample=True,
40
+ pad_token_id=tokenizer.eos_token_id,
41
+ repetition_penalty=1.1
42
+ )
43
+
44
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
45
+ return response
46
+
47
+ # Beautiful UI
48
+ with gr.Blocks(title="Sayanox AI Coder", theme=gr.themes.Dark()) as demo:
49
+ gr.Markdown("# 🔥 Sayanox AI Coder\n**Ultra Advanced Coding Assistant • Sayanox Private Limited**")
50
+
51
+ with gr.Row():
52
+ with gr.Column(scale=1):
53
+ lang = gr.Dropdown(
54
+ ["Python", "JavaScript", "TypeScript", "Java", "C++", "C#", "Go", "Rust", "PHP", "SQL", "HTML/CSS", "Bash", "Dart", "Kotlin", "Swift"],
55
+ value="Python",
56
+ label="Programming Language"
57
+ )
58
+ task = gr.Dropdown(
59
+ ["Generate Code", "Fix Bug", "Explain Code", "Optimize/Refactor", "Write Tests", "Code Review", "Full Stack Feature", "API Development"],
60
+ value="Generate Code",
61
+ label="Task"
62
+ )
63
+ temp = gr.Slider(0.1, 0.9, value=0.6, step=0.05, label="Temperature (Lower = More Accurate & Safe)")
64
+
65
+ with gr.Column(scale=3):
66
+ prompt = gr.Textbox(
67
+ lines=10,
68
+ placeholder="Describe your request in detail...\nExample: Create a FastAPI backend with user authentication using JWT and PostgreSQL...",
69
+ label="Your Request"
70
+ )
71
+
72
+ submit = gr.Button("🚀 Generate Advanced Code", variant="primary", size="large")
73
+
74
+ with gr.Row():
75
+ with gr.Column(scale=1):
76
+ explanation = gr.Textbox(label="Step-by-Step Explanation & Analysis", lines=12)
77
+ with gr.Column(scale=1):
78
+ code_output = gr.Code(label="Final Code (Double Checked)", language="python", lines=15, show_copy_button=True)
79
+
80
+ submit.click(
81
+ advanced_coding_ai,
82
+ inputs=[prompt, lang, task, temp],
83
+ outputs=[explanation]
84
+ )
85
+
86
+ gr.Markdown("### Made with ❤️ by Sayanox Private Limited")
87
+
88
+ demo.launch()