Al1Abdullah commited on
Commit
d529a20
·
verified ·
1 Parent(s): c384400

Create templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +190 -0
templates/index.html ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
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
+ .note { font-style: italic; color: #6c757d; }
38
+ .highlight {
39
+ background-color: #28a745;
40
+ color: white;
41
+ padding: 2px 8px;
42
+ border-radius: 4px;
43
+ font-weight: 600;
44
+ }
45
+ .highlight-warning {
46
+ background-color: #fd7e14;
47
+ }
48
+ .schema-summary h4 { margin-bottom: 10px; }
49
+ .schema-summary ul { margin-bottom: 15px; }
50
+ .schema-summary li { margin-bottom: 5px; }
51
+ .table {
52
+ border-radius: 8px;
53
+ overflow: hidden;
54
+ box-shadow: 0 2px 5px rgba(0,0,0,0.1);
55
+ }
56
+ .table thead th {
57
+ background-color: #007bff;
58
+ color: white;
59
+ font-weight: 600;
60
+ text-transform: capitalize;
61
+ padding: 12px;
62
+ }
63
+ .table tbody tr:nth-child(even) {
64
+ background-color: #f8f9fa;
65
+ }
66
+ .table tbody tr:hover {
67
+ background-color: #e9ecef;
68
+ transition: background-color 0.2s;
69
+ }
70
+ .table td {
71
+ padding: 12px;
72
+ vertical-align: middle;
73
+ }
74
+ .btn-primary {
75
+ background-color: #007bff;
76
+ border-color: #007bff;
77
+ padding: 10px 20px;
78
+ }
79
+ .btn-primary:hover {
80
+ background-color: #0056b3;
81
+ border-color: #0056b3;
82
+ }
83
+ .form-control {
84
+ border-radius: 5px;
85
+ }
86
+ .unpaid { color: #dc3545; font-weight: bold; }
87
+ </style>
88
+ </head>
89
+ <body>
90
+ <div class="container">
91
+ <h1 class="text-center mb-4">AI SQL Assistant</h1>
92
+
93
+ <form method="post" enctype="multipart/form-data" class="mb-4">
94
+ <div class="mb-3">
95
+ <label for="sql_file" class="form-label">Upload MySQL .sql File</label>
96
+ <input type="file" class="form-control" id="sql_file" name="sql_file" accept=".sql">
97
+ </div>
98
+ <button type="submit" class="btn btn-primary">Upload</button>
99
+ </form>
100
+
101
+ {% if summary %}
102
+ <div class="schema-box">
103
+ <h3>Database Summary</h3>
104
+ <div class="schema-summary">
105
+ <h4>Overview</h4>
106
+ <p>{{ summary.description }}</p>
107
+ <h4>Main Tables and Columns</h4>
108
+ <ul>
109
+ {% for table, columns in summary.main_tables.items() %}
110
+ <li><strong>{{ table }}</strong>: {{ columns | join(', ') }}</li>
111
+ {% endfor %}
112
+ </ul>
113
+ <h4>Key Relationships</h4>
114
+ <ul>
115
+ {% for relation in summary.relationships %}
116
+ <li>{{ relation }}</li>
117
+ {% endfor %}
118
+ </ul>
119
+ <h4>Suggestions</h4>
120
+ <p><span class="highlight {% if summary.suggestions.evaluation != 'Excellent' %}highlight-warning{% endif %}">{{ summary.suggestions.evaluation }}</span></p>
121
+ <p>{{ summary.suggestions.note }}</p>
122
+ <ul>
123
+ {% for rec in summary.suggestions.recommendations %}
124
+ <li>{{ rec }}</li>
125
+ {% endfor %}
126
+ </ul>
127
+ </div>
128
+ </div>
129
+ {% endif %}
130
+
131
+ <form method="post" class="mt-4">
132
+ <div class="mb-3">
133
+ <label for="question" class="form-label">Ask a Question</label>
134
+ <input type="text" class="form-control" id="question" name="question" placeholder="e.g., Show all patients admitted in July 2025">
135
+ </div>
136
+ <button type="submit" class="btn btn-primary">Submit</button>
137
+ </form>
138
+
139
+ {% if error %}
140
+ <p class="error mt-3">{{ error }}</p>
141
+ {% endif %}
142
+
143
+ {% if query %}
144
+ <div class="query-box">
145
+ <button class="toggle-button" onclick="toggleSection('query-content')">View SQL Query</button>
146
+ <div id="query-content" class="query-content">
147
+ <pre class="bg-light p-3 rounded">{{ query }}</pre>
148
+ </div>
149
+ </div>
150
+ {% endif %}
151
+
152
+ {% if results %}
153
+ <div class="result-table">
154
+ <h4>Query Results</h4>
155
+ <table class="table table-bordered">
156
+ <thead>
157
+ <tr>
158
+ {% for key in results[0].keys() %}
159
+ <th>{{ key }}</th>
160
+ {% endfor %}
161
+ </tr>
162
+ </thead>
163
+ <tbody>
164
+ {% for row in results %}
165
+ <tr>
166
+ {% for key, value in row.items() %}
167
+ <td {% if key in ['Total Bill Amount', 'Bill Amount'] %}class="unpaid"{% endif %}>{{ value }}</td>
168
+ {% endfor %}
169
+ </tr>
170
+ {% endfor %}
171
+ </tbody>
172
+ </table>
173
+ </div>
174
+ {% elif query and not error %}
175
+ <p class="note mt-3">No results found for the query. Check the data or try a different question.</p>
176
+ {% endif %}
177
+ </div>
178
+
179
+ <script>
180
+ function toggleSection(id) {
181
+ const content = document.getElementById(id);
182
+ if (content.style.display === 'none' || content.style.display === '') {
183
+ content.style.display = 'block';
184
+ } else {
185
+ content.style.display = 'none';
186
+ }
187
+ }
188
+ </script>
189
+ </body>
190
+ </html>