Spaces:
Runtime error
Runtime error
Delete templates/index.html
Browse files- templates/index.html +0 -263
templates/index.html
DELETED
|
@@ -1,263 +0,0 @@
|
|
| 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 |
-
.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 |
-
.welcome-note {
|
| 97 |
-
background-color: #e9ecef;
|
| 98 |
-
padding: 15px;
|
| 99 |
-
border-radius: 8px;
|
| 100 |
-
margin-bottom: 20px;
|
| 101 |
-
}
|
| 102 |
-
</style>
|
| 103 |
-
</head>
|
| 104 |
-
<body>
|
| 105 |
-
<div class="container">
|
| 106 |
-
<h1 class="text-center mb-4">AI SQL Assistant</h1>
|
| 107 |
-
<div class="welcome-note">
|
| 108 |
-
<p class="mb-0">This app uses a default TiDB Serverless database for instant access. Use the "Configure MySQL Connection" modal to connect to a custom database.</p>
|
| 109 |
-
</div>
|
| 110 |
-
|
| 111 |
-
<div class="mb-4">
|
| 112 |
-
<button type="button" class="btn btn-primary me-2" data-bs-toggle="modal" data-bs-target="#dbConfigModal">Configure MySQL Connection</button>
|
| 113 |
-
<form method="post" action="/reset_db" style="display: inline;">
|
| 114 |
-
<button type="submit" class="btn btn-primary me-2">Reset to Default Connection</button>
|
| 115 |
-
</form>
|
| 116 |
-
<form method="post" enctype="multipart/form-data" style="display: inline;">
|
| 117 |
-
<div class="mb-3 d-inline-block">
|
| 118 |
-
<label for="sql_file" class="form-label">Upload MySQL .sql File</label>
|
| 119 |
-
<input type="file" class="form-control" id="sql_file" name="sql_file" accept=".sql">
|
| 120 |
-
</div>
|
| 121 |
-
<button type="submit" class="btn btn-primary">Upload</button>
|
| 122 |
-
</form>
|
| 123 |
-
</div>
|
| 124 |
-
|
| 125 |
-
<!-- Modal for MySQL Connection -->
|
| 126 |
-
<div class="modal fade" id="dbConfigModal" tabindex="-1" aria-labelledby="dbConfigModalLabel" aria-hidden="true">
|
| 127 |
-
<div class="modal-dialog">
|
| 128 |
-
<div class="modal-content">
|
| 129 |
-
<div class="modal-header">
|
| 130 |
-
<h5 class="modal-title" id="dbConfigModalLabel">Configure MySQL Connection</h5>
|
| 131 |
-
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
| 132 |
-
</div>
|
| 133 |
-
<div class="modal-body">
|
| 134 |
-
<form method="post" action="/configure_db">
|
| 135 |
-
<div class="mb-3">
|
| 136 |
-
<label for="host" class="form-label">Host</label>
|
| 137 |
-
<input type="text" class="form-control" id="host" name="host" placeholder="e.g., gateway01.ap-southeast-1.prod.aws.tidbcloud.com" required>
|
| 138 |
-
</div>
|
| 139 |
-
<div class="mb-3">
|
| 140 |
-
<label for="user" class="form-label">User</label>
|
| 141 |
-
<input type="text" class="form-control" id="user" name="user" placeholder="e.g., root" required>
|
| 142 |
-
</div>
|
| 143 |
-
<div class="mb-3">
|
| 144 |
-
<label for="password" class="form-label">Password</label>
|
| 145 |
-
<input type="password" class="form-control" id="password" name="password" placeholder="Enter password">
|
| 146 |
-
</div>
|
| 147 |
-
<div class="mb-3">
|
| 148 |
-
<label for="port" class="form-label">Port</label>
|
| 149 |
-
<input type="number" class="form-control" id="port" name="port" placeholder="4000" value="4000">
|
| 150 |
-
</div>
|
| 151 |
-
<button type="submit" class="btn btn-primary">Save Connection</button>
|
| 152 |
-
</form>
|
| 153 |
-
</div>
|
| 154 |
-
</div>
|
| 155 |
-
</div>
|
| 156 |
-
</div>
|
| 157 |
-
|
| 158 |
-
{% if success %}
|
| 159 |
-
<p class="success mt-3">{{ success }}</p>
|
| 160 |
-
{% endif %}
|
| 161 |
-
|
| 162 |
-
{% if summary %}
|
| 163 |
-
<div class="schema-box">
|
| 164 |
-
<h3>Database Summary</h3>
|
| 165 |
-
<div class="schema-summary">
|
| 166 |
-
<h4>Overview</h4>
|
| 167 |
-
<p>{{ summary.description }}</p>
|
| 168 |
-
{% if summary.main_tables %}
|
| 169 |
-
<h4>Main Tables and Columns</h4>
|
| 170 |
-
<ul>
|
| 171 |
-
{% for table, columns in summary.main_tables.items() %}
|
| 172 |
-
<li><strong>{{ table }}</strong>: {{ columns | join(', ') }}</li>
|
| 173 |
-
{% endfor %}
|
| 174 |
-
</ul>
|
| 175 |
-
{% endif %}
|
| 176 |
-
{% if summary.relationships %}
|
| 177 |
-
<h4>Key Relationships</h4>
|
| 178 |
-
<ul>
|
| 179 |
-
{% for relation in summary.relationships %}
|
| 180 |
-
<li>{{ relation }}</li>
|
| 181 |
-
{% endfor %}
|
| 182 |
-
</ul>
|
| 183 |
-
{% endif %}
|
| 184 |
-
<h4>Suggestions</h4>
|
| 185 |
-
<p><span class="highlight {% if summary.suggestions.evaluation != 'Excellent' %}highlight-warning{% endif %}">{{ summary.suggestions.evaluation }}</span></p>
|
| 186 |
-
<p>{{ summary.suggestions.note }}</p>
|
| 187 |
-
{% if summary.suggestions.recommendations %}
|
| 188 |
-
<ul>
|
| 189 |
-
{% for rec in summary.suggestions.recommendations %}
|
| 190 |
-
<li>{{ rec }}</li>
|
| 191 |
-
{% endfor %}
|
| 192 |
-
</ul>
|
| 193 |
-
{% endif %}
|
| 194 |
-
</div>
|
| 195 |
-
</div>
|
| 196 |
-
{% elif schema %}
|
| 197 |
-
<div class="schema-box">
|
| 198 |
-
<h3>Database Summary</h3>
|
| 199 |
-
<p class="note">Schema loaded, but no summary available. Tables: {{ schema.keys() | join(', ') }}.</p>
|
| 200 |
-
</div>
|
| 201 |
-
{% endif %}
|
| 202 |
-
|
| 203 |
-
<form method="post" class="mt-4">
|
| 204 |
-
<div class="mb-3">
|
| 205 |
-
<label for="question" class="form-label">Ask a Question</label>
|
| 206 |
-
<input type="text" class="form-control" id="question" name="question" placeholder="e.g., Show all patients admitted in July 2025">
|
| 207 |
-
</div>
|
| 208 |
-
<button type="submit" class="btn btn-primary">Submit</button>
|
| 209 |
-
</form>
|
| 210 |
-
|
| 211 |
-
{% if error %}
|
| 212 |
-
<p class="error mt-3">{{ error }}</p>
|
| 213 |
-
{% endif %}
|
| 214 |
-
|
| 215 |
-
{% if query %}
|
| 216 |
-
<div class="query-box">
|
| 217 |
-
<button class="toggle-button" onclick="toggleSection('query-content')">View SQL Query</button>
|
| 218 |
-
<div id="query-content" class="query-content">
|
| 219 |
-
<pre class="bg-light p-3 rounded">{{ query }}</pre>
|
| 220 |
-
</div>
|
| 221 |
-
</div>
|
| 222 |
-
{% endif %}
|
| 223 |
-
|
| 224 |
-
{% if results %}
|
| 225 |
-
<div class="result-table">
|
| 226 |
-
<h4>Query Results</h4>
|
| 227 |
-
<table class="table table-bordered">
|
| 228 |
-
<thead>
|
| 229 |
-
<tr>
|
| 230 |
-
{% for key in results[0].keys() %}
|
| 231 |
-
<th>{{ key }}</th>
|
| 232 |
-
{% endfor %}
|
| 233 |
-
</tr>
|
| 234 |
-
</thead>
|
| 235 |
-
<tbody>
|
| 236 |
-
{% for row in results %}
|
| 237 |
-
<tr>
|
| 238 |
-
{% for key, value in row.items() %}
|
| 239 |
-
<td {% if key in ['Total Bill Amount', 'Bill Amount'] %}class="unpaid"{% endif %}>{{ value }}</td>
|
| 240 |
-
{% endfor %}
|
| 241 |
-
</tr>
|
| 242 |
-
{% endfor %}
|
| 243 |
-
</tbody>
|
| 244 |
-
</table>
|
| 245 |
-
</div>
|
| 246 |
-
{% elif query and not error %}
|
| 247 |
-
<p class="note mt-3">No results found for the query. Check the data or try a different question.</p>
|
| 248 |
-
{% endif %}
|
| 249 |
-
</div>
|
| 250 |
-
|
| 251 |
-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
| 252 |
-
<script>
|
| 253 |
-
function toggleSection(id) {
|
| 254 |
-
const content = document.getElementById(id);
|
| 255 |
-
if (content.style.display === 'none' || content.style.display === '') {
|
| 256 |
-
content.style.display = 'block';
|
| 257 |
-
} else {
|
| 258 |
-
content.style.display = 'none';
|
| 259 |
-
}
|
| 260 |
-
}
|
| 261 |
-
</script>
|
| 262 |
-
</body>
|
| 263 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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