Al1Abdullah commited on
Commit
2b81aa6
·
verified ·
1 Parent(s): de187e0

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +170 -207
templates/index.html CHANGED
@@ -4,248 +4,211 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>AI SQL Assistant</title>
7
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
8
  <style>
9
- body { background-color: #f8f9fa; }
10
- .container { max-width: 900px; margin-top: 20px; }
11
- .schema-box, .query-box {
12
- background-color: #fff;
13
- padding: 20px;
14
- border-radius: 8px;
15
- box-shadow: 0 4px 10px rgba(0,0,0,0.1);
16
- margin-bottom: 20px;
17
- }
18
- .query-box { display: block; }
19
- .query-content { display: none; }
20
- .toggle-button {
21
- background-color: #007bff;
22
- color: white;
23
- border: none;
24
- padding: 8px 15px;
25
- border-radius: 5px;
26
- cursor: pointer;
27
- font-weight: 500;
28
- font-size: 0.9rem;
29
- width: auto;
30
- display: inline-block;
31
- }
32
- .toggle-button:hover {
33
- background-color: #0056b3;
34
- }
35
- .result-table { margin-top: 20px; }
36
- .error { color: #dc3545; font-weight: 500; }
37
- .success { color: #28a745; font-weight: 500; }
38
- .note { font-style: italic; color: #6c757d; }
39
- .highlight {
40
- background-color: #28a745;
41
- color: white;
42
- padding: 2px 8px;
43
- border-radius: 4px;
44
- font-weight: 600;
45
- }
46
- .highlight-warning {
47
- background-color: #fd7e14;
48
- }
49
- .schema-summary h4 { margin-bottom: 10px; }
50
- .schema-summary ul { margin-bottom: 15px; }
51
- .schema-summary li { margin-bottom: 5px; }
52
- .table {
53
- border-radius: 8px;
54
- overflow: hidden;
55
- box-shadow: 0 2px 5px rgba(0,0,0,0.1);
56
- }
57
- .table thead th {
58
- background-color: #007bff;
59
- color: white;
60
- font-weight: 600;
61
- text-transform: capitalize;
62
- padding: 12px;
63
- }
64
- .table tbody tr:nth-child(even) {
65
- background-color: #f8f9fa;
66
- }
67
- .table tbody tr:hover {
68
- background-color: #e9ecef;
69
- transition: background-color 0.2s;
70
- }
71
- .table td {
72
- padding: 12px;
73
- vertical-align: middle;
74
- }
75
- .btn-primary {
76
- background-color: #007bff;
77
- border-color: #007bff;
78
- padding: 10px 20px;
79
- }
80
- .btn-primary:hover {
81
- background-color: #0056b3;
82
- border-color: #0056b3;
83
- }
84
- .form-control {
85
- border-radius: 5px;
86
- }
87
- .unpaid { color: #dc3545; font-weight: bold; }
88
- .modal-content {
89
- border-radius: 8px;
90
- box-shadow: 0 4px 10px rgba(0,0,0,0.1);
91
- }
92
- .modal-header {
93
- background-color: #007bff;
94
- color: white;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  }
96
  </style>
97
  </head>
98
  <body>
99
  <div class="container">
100
- <h1 class="text-center mb-4">AI SQL Assistant</h1>
101
-
102
- <div class="mb-4">
103
- <button type="button" class="btn btn-primary me-2" data-bs-toggle="modal" data-bs-target="#dbConfigModal">Configure MySQL Connection</button>
104
- <form method="post" enctype="multipart/form-data" style="display: inline;">
105
- <div class="mb-3 d-inline-block">
106
- <label for="sql_file" class="form-label">Upload MySQL .sql File</label>
107
- <input type="file" class="form-control" id="sql_file" name="sql_file" accept=".sql">
108
- </div>
109
- <button type="submit" class="btn btn-primary">Upload</button>
110
- </form>
111
- </div>
112
-
113
- <!-- Modal for MySQL Connection -->
114
- <div class="modal fade" id="dbConfigModal" tabindex="-1" aria-labelledby="dbConfigModalLabel" aria-hidden="true">
115
- <div class="modal-dialog">
116
- <div class="modal-content">
117
- <div class="modal-header">
118
- <h5 class="modal-title" id="dbConfigModalLabel">Configure MySQL Connection</h5>
119
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
120
- </div>
121
- <div class="modal-body">
122
- <form method="post" action="/configure_db">
123
- <div class="mb-3">
124
- <label for="host" class="form-label">Host</label>
125
- <input type="text" class="form-control" id="host" name="host" placeholder="e.g., localhost" required>
126
- </div>
127
- <div class="mb-3">
128
- <label for="user" class="form-label">User</label>
129
- <input type="text" class="form-control" id="user" name="user" placeholder="e.g., root" required>
130
- </div>
131
- <div class="mb-3">
132
- <label for="password" class="form-label">Password</label>
133
- <input type="password" class="form-control" id="password" name="password" placeholder="Enter password">
134
- </div>
135
- <div class="mb-3">
136
- <label for="port" class="form-label">Port</label>
137
- <input type="number" class="form-control" id="port" name="port" placeholder="3306" value="3306">
138
- </div>
139
- <button type="submit" class="btn btn-primary">Save Connection</button>
140
- </form>
141
- </div>
142
- </div>
143
- </div>
144
- </div>
145
-
146
  {% if success %}
147
- <p class="success mt-3">{{ success }}</p>
148
  {% endif %}
149
-
150
- {% if summary %}
151
- <div class="schema-box">
152
- <h3>Database Summary</h3>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  <div class="schema-summary">
154
- <h4>Overview</h4>
155
- <p>{{ summary.description }}</p>
156
- {% if summary.main_tables %}
157
- <h4>Main Tables and Columns</h4>
158
  <ul>
159
  {% for table, columns in summary.main_tables.items() %}
160
- <li><strong>{{ table }}</strong>: {{ columns | join(', ') }}</li>
161
  {% endfor %}
162
  </ul>
163
- {% endif %}
164
- {% if summary.relationships %}
165
- <h4>Key Relationships</h4>
166
  <ul>
167
- {% for relation in summary.relationships %}
168
- <li>{{ relation }}</li>
169
  {% endfor %}
170
  </ul>
171
- {% endif %}
172
- <h4>Suggestions</h4>
173
- <p><span class="highlight {% if summary.suggestions.evaluation != 'Excellent' %}highlight-warning{% endif %}">{{ summary.suggestions.evaluation }}</span></p>
174
- <p>{{ summary.suggestions.note }}</p>
175
- {% if summary.suggestions.recommendations %}
176
  <ul>
177
  {% for rec in summary.suggestions.recommendations %}
178
- <li>{{ rec }}</li>
179
  {% endfor %}
180
  </ul>
181
- {% endif %}
182
  </div>
183
- </div>
184
- {% elif schema %}
185
- <div class="schema-box">
186
- <h3>Database Summary</h3>
187
- <p class="note">Schema loaded, but no summary available. Tables: {{ schema.keys() | join(', ') }}.</p>
188
- </div>
189
  {% endif %}
190
-
191
- <form method="post" class="mt-4">
192
- <div class="mb-3">
193
- <label for="question" class="form-label">Ask a Question</label>
194
- <input type="text" class="form-control" id="question" name="question" placeholder="e.g., Show all patients admitted in July 2025">
195
- </div>
196
- <button type="submit" class="btn btn-primary">Submit</button>
197
  </form>
198
-
199
- {% if error %}
200
- <p class="error mt-3">{{ error }}</p>
201
- {% endif %}
202
-
203
  {% if query %}
204
- <div class="query-box">
205
- <button class="toggle-button" onclick="toggleSection('query-content')">View SQL Query</button>
206
- <div id="query-content" class="query-content">
207
- <pre class="bg-light p-3 rounded">{{ query }}</pre>
208
  </div>
209
- </div>
210
  {% endif %}
211
-
212
-
213
  {% if results %}
214
- <div class="result-table">
215
- <h4>Query Results</h4>
216
- <table class="table table-bordered">
217
- <thead>
218
- <tr>
219
- {% for key in results[0].keys() %}
220
  <th>{{ key }}</th>
221
- {% endfor %}
222
- </tr>
223
- </thead>
224
- <tbody>
225
- {% for row in results %}
226
  <tr>
227
- {% for key, value in row.items() %}
228
- <td {% if key in ['Total Bill Amount', 'Bill Amount'] %}class="unpaid"{% endif %}>{{ value }}</td>
229
  {% endfor %}
230
  </tr>
231
- {% endfor %}
232
- </tbody>
233
  </table>
234
- </div>
235
- {% elif query and not error %}
236
- <p class="note mt-3">No results found for the query. Check the data or try a different question.</p>
237
  {% endif %}
238
  </div>
239
-
240
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
241
  <script>
242
- function toggleSection(id) {
243
- const content = document.getElementById(id);
244
- if (content.style.display === 'none' || content.style.display === '') {
245
- content.style.display = 'block';
246
- } else {
247
- content.style.display = 'none';
248
- }
249
  }
250
  </script>
251
  </body>
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>AI SQL Assistant</title>
 
7
  <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ margin: 20px;
11
+ background-color: #f4f4f9;
12
+ }
13
+ h1 {
14
+ color: #333;
15
+ }
16
+ .container {
17
+ max-width: 800px;
18
+ margin: auto;
19
+ padding: 20px;
20
+ background: white;
21
+ border-radius: 8px;
22
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
23
+ }
24
+ .error {
25
+ color: red;
26
+ margin: 10px 0;
27
+ }
28
+ .success {
29
+ color: green;
30
+ margin: 10px 0;
31
+ }
32
+ .schema-summary {
33
+ margin: 20px 0;
34
+ padding: 10px;
35
+ border: 1px solid #ddd;
36
+ border-radius: 4px;
37
+ }
38
+ .schema-summary h3 {
39
+ margin-top: 0;
40
+ }
41
+ .schema-summary ul {
42
+ list-style-type: disc;
43
+ margin-left: 20px;
44
+ }
45
+ .results-table {
46
+ width: 100%;
47
+ border-collapse: collapse;
48
+ margin: 20px 0;
49
+ }
50
+ .results-table th, .results-table td {
51
+ border: 1px solid #ddd;
52
+ padding: 8px;
53
+ text-align: left;
54
+ }
55
+ .results-table th {
56
+ background-color: #f2f2f2;
57
+ }
58
+ .query-box {
59
+ margin: 20px 0;
60
+ padding: 10px;
61
+ border: 1px solid #ddd;
62
+ border-radius: 4px;
63
+ }
64
+ textarea, input[type="text"], input[type="file"] {
65
+ width: 100%;
66
+ padding: 8px;
67
+ margin: 5px 0;
68
+ border: 1px solid #ddd;
69
+ border-radius: 4px;
70
+ }
71
+ button {
72
+ padding: 10px 20px;
73
+ background-color: #007bff;
74
+ color: white;
75
+ border: none;
76
+ border-radius: 4px;
77
+ cursor: pointer;
78
+ }
79
+ button:hover {
80
+ background-color: #0056b3;
81
+ }
82
+ .modal {
83
+ display: none;
84
+ position: fixed;
85
+ top: 0;
86
+ left: 0;
87
+ width: 100%;
88
+ height: 100%;
89
+ background-color: rgba(0,0,0,0.5);
90
+ justify-content: center;
91
+ align-items: center;
92
+ }
93
+ .modal-content {
94
+ background: white;
95
+ padding: 20px;
96
+ border-radius: 8px;
97
+ width: 400px;
98
+ }
99
+ .modal-content h2 {
100
+ margin-top: 0;
101
+ }
102
+ .modal-content label {
103
+ display: block;
104
+ margin: 10px 0 5px;
105
+ }
106
+ .modal-content input {
107
+ width: calc(100% - 16px);
108
+ }
109
+ .close {
110
+ float: right;
111
+ font-size: 24px;
112
+ cursor: pointer;
113
  }
114
  </style>
115
  </head>
116
  <body>
117
  <div class="container">
118
+ <h1>AI SQL Assistant</h1>
119
+ {% if error %}
120
+ <p class="error">{{ error }}</p>
121
+ {% endif %}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  {% if success %}
123
+ <p class="success">{{ success }}</p>
124
  {% endif %}
125
+ <form method="post" enctype="multipart/form-data">
126
+ <label for="sql_file">Upload MySQL .sql File</label>
127
+ <input type="file" id="sql_file" name="sql_file" accept=".sql">
128
+ <button type="submit">Upload</button>
129
+ </form>
130
+ <button onclick="openModal()">Configure MySQL Connection</button>
131
+ <form method="post" action="/reset_db">
132
+ <button type="submit">Reset to Default Connection</button>
133
+ </form>
134
+ <div id="dbModal" class="modal">
135
+ <div class="modal-content">
136
+ <span class="close" onclick="closeModal()">&times;</span>
137
+ <h2>Configure MySQL Connection</h2>
138
+ <form method="post" action="/configure_db">
139
+ <label for="host">Host</label>
140
+ <input type="text" id="host" name="host" placeholder="e.g., gateway01.ap-southeast-1.prod.aws.tidbcloud.com">
141
+ <label for="user">User</label>
142
+ <input type="text" id="user" name="user" placeholder="e.g., 31QbJgnPtKiyvcC.root">
143
+ <label for="password">Password</label>
144
+ <input type="password" id="password" name="password">
145
+ <label for="port">Port</label>
146
+ <input type="text" id="port" name="port" value="4000">
147
+ <button type="submit">Save</button>
148
+ </form>
149
+ </div>
150
+ </div>
151
+ {% if schema %}
152
  <div class="schema-summary">
153
+ <h3>Schema Summary</h3>
154
+ <p><strong>Description:</strong> {{ summary.description }}</p>
155
+ <h4>Main Tables:</h4>
 
156
  <ul>
157
  {% for table, columns in summary.main_tables.items() %}
158
+ <li>{{ table }}: {{ columns | join(', ') }}</li>
159
  {% endfor %}
160
  </ul>
161
+ <h4>Relationships:</h4>
 
 
162
  <ul>
163
+ {% for rel in summary.relationships %}
164
+ <li>{{ rel }}</li>
165
  {% endfor %}
166
  </ul>
167
+ <h4>Suggestions:</h4>
168
+ <p><strong>Evaluation:</strong> {{ summary.suggestions.evaluation }}</p>
169
+ <p><strong>Note:</strong> {{ summary.suggestions.note }}</p>
 
 
170
  <ul>
171
  {% for rec in summary.suggestions.recommendations %}
172
+ <li>{{ rec }}</li>
173
  {% endfor %}
174
  </ul>
 
175
  </div>
 
 
 
 
 
 
176
  {% endif %}
177
+ <form method="post">
178
+ <label for="question">Ask a Question</label>
179
+ <textarea id="question" name="question" placeholder="e.g., Show all patients admitted in July 2025"></textarea>
180
+ <button type="submit">Submit</button>
 
 
 
181
  </form>
 
 
 
 
 
182
  {% if query %}
183
+ <div class="query-box">
184
+ <h3>Generated SQL Query</h3>
185
+ <pre>{{ query }}</pre>
 
186
  </div>
 
187
  {% endif %}
 
 
188
  {% if results %}
189
+ <h3>Query Results</h3>
190
+ <table class="results-table">
191
+ <tr>
192
+ {% for key in results[0].keys() %}
 
 
193
  <th>{{ key }}</th>
194
+ {% endfor %}
195
+ </tr>
196
+ {% for row in results %}
 
 
197
  <tr>
198
+ {% for value in row.values() %}
199
+ <td>{{ value }}</td>
200
  {% endfor %}
201
  </tr>
202
+ {% endfor %}
 
203
  </table>
 
 
 
204
  {% endif %}
205
  </div>
 
 
206
  <script>
207
+ function openModal() {
208
+ document.getElementById('dbModal').style.display = 'flex';
209
+ }
210
+ function closeModal() {
211
+ document.getElementById('dbModal').style.display = 'none';
 
 
212
  }
213
  </script>
214
  </body>