Spaces:
Runtime error
Runtime error
Update templates/index.html
Browse files- templates/index.html +207 -170
templates/index.html
CHANGED
|
@@ -4,211 +4,248 @@
|
|
| 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 |
-
|
| 10 |
-
|
| 11 |
-
background-color: #
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
background:
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
}
|
| 38 |
-
.
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
}
|
| 45 |
-
.
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
}
|
| 50 |
-
.
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
border-
|
| 77 |
-
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
background-color: #0056b3;
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 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 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
</
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
<
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
</div>
|
| 150 |
</div>
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
<div class="schema-summary">
|
| 153 |
-
<
|
| 154 |
-
<p
|
| 155 |
-
|
|
|
|
| 156 |
<ul>
|
| 157 |
{% for table, columns in summary.main_tables.items() %}
|
| 158 |
-
|
| 159 |
{% endfor %}
|
| 160 |
</ul>
|
| 161 |
-
|
|
|
|
|
|
|
| 162 |
<ul>
|
| 163 |
-
{% for
|
| 164 |
-
|
| 165 |
{% endfor %}
|
| 166 |
</ul>
|
| 167 |
-
|
| 168 |
-
<
|
| 169 |
-
<p><
|
|
|
|
|
|
|
| 170 |
<ul>
|
| 171 |
{% for rec in summary.suggestions.recommendations %}
|
| 172 |
-
|
| 173 |
{% endfor %}
|
| 174 |
</ul>
|
|
|
|
| 175 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
{% endif %}
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
<
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
| 181 |
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
{% if query %}
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
|
|
|
| 186 |
</div>
|
|
|
|
| 187 |
{% endif %}
|
|
|
|
|
|
|
| 188 |
{% if results %}
|
| 189 |
-
|
| 190 |
-
<
|
| 191 |
-
|
| 192 |
-
|
|
|
|
|
|
|
| 193 |
<th>{{ key }}</th>
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
| 197 |
<tr>
|
| 198 |
-
{% for value in row.
|
| 199 |
-
|
| 200 |
{% endfor %}
|
| 201 |
</tr>
|
| 202 |
-
|
|
|
|
| 203 |
</table>
|
|
|
|
|
|
|
|
|
|
| 204 |
{% endif %}
|
| 205 |
</div>
|
|
|
|
|
|
|
| 206 |
<script>
|
| 207 |
-
function
|
| 208 |
-
document.getElementById(
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
|
|
|
|
|
|
| 212 |
}
|
| 213 |
</script>
|
| 214 |
</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 |
+
<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>
|