MalikShehram commited on
Commit
05c98e4
Β·
verified Β·
1 Parent(s): 609ce86

Create static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +254 -0
static/index.html ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <title>AI Code Commentor & Documenter</title>
8
+ <link href="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/themes/prism.css" rel="stylesheet">
9
+ <style>
10
+ * {
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ body {
15
+ font-family: sans-serif;
16
+ padding: 1.5rem;
17
+ background: #f5f5f5;
18
+ margin: 0;
19
+ }
20
+
21
+ textarea,
22
+ input[type="file"],
23
+ button {
24
+ margin-top: 1rem;
25
+ display: block;
26
+ }
27
+
28
+ textarea {
29
+ width: 100%;
30
+ height: 200px;
31
+ font-family: monospace;
32
+ padding: 1rem;
33
+ font-size: 1rem;
34
+ color: #495057;
35
+ background-color: #f8f9fa;
36
+ border: 1px solid #ced4da;
37
+ border-radius: 0.375rem;
38
+ }
39
+
40
+ .file-upload-container {
41
+ width: 100%;
42
+ border: 1px solid #ced4da;
43
+ padding: 1rem;
44
+ border-radius: 0.375rem;
45
+ margin-bottom: 1rem;
46
+ background-color: #f8f9fa;
47
+ }
48
+
49
+ input[type="file"].form-control {
50
+ padding: 0.375rem 0.75rem;
51
+ font-size: 1rem;
52
+ line-height: 1.5;
53
+ color: #495057;
54
+ background-color: #fff;
55
+ background-clip: padding-box;
56
+ border: 1px solid #ced4da;
57
+ border-radius: 0.375rem;
58
+ }
59
+
60
+ .section {
61
+ margin-top: 2rem;
62
+ }
63
+
64
+ pre {
65
+ background: #2d2d2d;
66
+ color: #f8f8f2;
67
+ padding: 1rem;
68
+ border-radius: 6px;
69
+ overflow-x: auto;
70
+ font-size: 0.9rem;
71
+ }
72
+
73
+ h1 {
74
+ font-size: 1.75rem;
75
+ margin-bottom: 1.5rem;
76
+ }
77
+
78
+ .btn-group {
79
+ display: flex;
80
+ flex-direction: column;
81
+ gap: 0.75rem;
82
+ }
83
+
84
+ .btn-group button {
85
+ padding: 0.75rem;
86
+ font-size: 1rem;
87
+ border-radius: 0.375rem;
88
+ border: none;
89
+ cursor: pointer;
90
+ background-color: #007bff;
91
+ color: white;
92
+ }
93
+
94
+ .btn-group button:disabled {
95
+ background-color: #adb5bd;
96
+ cursor: not-allowed;
97
+ }
98
+
99
+ footer {
100
+ background-color: #f8f9fa;
101
+ border-top: 1px solid #ddd;
102
+ padding: 1rem;
103
+ margin-top: 2rem;
104
+ text-align: center;
105
+ font-size: 0.9rem;
106
+ color: #555;
107
+ }
108
+
109
+ @media (min-width: 600px) {
110
+ .btn-group {
111
+ flex-direction: row;
112
+ justify-content: flex-start;
113
+ }
114
+
115
+ .btn-group button {
116
+ width: auto;
117
+ }
118
+ }
119
+ </style>
120
+ </head>
121
+
122
+ <body>
123
+
124
+ <h1>🧠 AI Code Comment & Documentation Generator</h1>
125
+
126
+ <form id="codeForm">
127
+ <label for="codeInput">Paste your code:</label>
128
+ <textarea id="codeInput" name="code" class="text-area" placeholder="def add(a, b):
129
+ return a + b"></textarea>
130
+
131
+ <label for="fileInput">Or choose a file:</label>
132
+ <div class="file-upload-container">
133
+ <input class="form-control" type="file" id="fileInput" name="file"
134
+ accept=".txt,.js,.py,.cpp,.java,.ts">
135
+ </div>
136
+
137
+ <div style="display: flex; gap: 1rem;">
138
+ <button type="submit" id="generateBtn" disabled>⚑ Generate</button>
139
+ <button type="button" id="resetBtn">πŸ”„ Reset</button>
140
+ </div>
141
+
142
+ </form>
143
+
144
+ <div class="section">
145
+ <h2>πŸ“ Commented Code</h2>
146
+ <pre><code id="commentedCode" class="language-python"></code></pre>
147
+ </div>
148
+
149
+ <div class="section">
150
+ <h2>πŸ“˜ Documentation (JSON)</h2>
151
+ <pre><code id="jsonDoc" class="language-json"></code></pre>
152
+ </div>
153
+
154
+ <div class="section">
155
+ <h2>πŸš€ Improvements & Analysis</h2>
156
+ <pre><code id="improvement" class="language-markup"></code></pre>
157
+ </div>
158
+
159
+ <script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/prism.js"></script>
160
+ <script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-python.min.js"></script>
161
+ <script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-json.min.js"></script>
162
+
163
+ <script>
164
+ const codeInput = document.getElementById('codeInput');
165
+ const fileInput = document.getElementById('fileInput');
166
+ const generateBtn = document.getElementById('generateBtn');
167
+ const resetBtn = document.getElementById('resetBtn');
168
+ const form = document.getElementById('codeForm');
169
+
170
+ // Enable button if code or file is present
171
+ function updateButtonState() {
172
+ generateBtn.disabled = !(codeInput.value.trim() || fileInput.files.length);
173
+ }
174
+
175
+ codeInput.addEventListener('input', updateButtonState);
176
+ fileInput.addEventListener('change', updateButtonState);
177
+
178
+ form.addEventListener('submit', async (e) => {
179
+ e.preventDefault();
180
+ generateBtn.disabled = true;
181
+ generateBtn.textContent = '⏳ Generating...';
182
+
183
+ const formData = new FormData();
184
+ if (fileInput.files.length) {
185
+ formData.append('file', fileInput.files[0]);
186
+ } else {
187
+ formData.append('code', codeInput.value);
188
+ }
189
+
190
+ try {
191
+ const res = await fetch('/generate-docs', {
192
+ method: 'POST',
193
+ body: formData,
194
+ });
195
+
196
+ if (!res.ok) throw new Error(await res.text());
197
+ const data = await res.json();
198
+
199
+ // Unwrap formatted content
200
+ const [commented, json, improvement] = data.map(section =>
201
+ section.replace(/^```[a-z]*\n?/, '').replace(/```$/, '')
202
+ );
203
+
204
+ document.getElementById('commentedCode').textContent = commented;
205
+ document.getElementById('jsonDoc').textContent = json;
206
+ document.getElementById('improvement').textContent = improvement;
207
+
208
+ Prism.highlightAll();
209
+ generateBtn.textContent = 'βœ… Done!';
210
+ } catch (err) {
211
+ alert("❌ Error: " + err.message);
212
+ generateBtn.textContent = '⚑ Generate';
213
+ }
214
+ resetBtn.disabled = false;
215
+ generateBtn.disabled = true;
216
+ });
217
+
218
+ resetBtn.addEventListener('click', () => {
219
+ codeInput.value = '';
220
+ fileInput.value = '';
221
+ document.getElementById('commentedCode').textContent = '';
222
+ document.getElementById('jsonDoc').textContent = '';
223
+ document.getElementById('improvement').textContent = '';
224
+ updateButtonState();
225
+ resetBtn.disabled = true;
226
+ generateBtn.textContent = '⚑ Generate';
227
+ });
228
+
229
+ fileInput.addEventListener("change", (e) => {
230
+ const file = e.target.files[0]
231
+ if (!file) return
232
+ generateBtn.disabled = false;
233
+ resetBtn.disabled = false;
234
+ const reader = new FileReader()
235
+ reader.onload = (e2) => {
236
+ const content = e2.target.result;
237
+ codeInput.textContent = content
238
+ }
239
+ reader.onerror = err => {
240
+ alert("Error occurred while reading file!");
241
+ console.error(err)
242
+ }
243
+ reader.readAsText(file)
244
+ })
245
+ </script>
246
+
247
+ <footer
248
+ style="background-color: #f8f9fa; border-top: 1px solid #ddd; padding: 1rem; margin-top: 2rem; text-align: center; font-size: 0.95rem; color: #555;">
249
+ <p style="margin: 0.3rem 0;">&copy; 2025 Hackathon Project</p>
250
+ <p style="margin: 0.3rem 0;">Built with πŸ’‘ by a team of 6</p>
251
+ </footer>
252
+ </body>
253
+
254
+ </html>