Spaces:
Runtime error
Runtime error
Update templates/index.html
Browse files- 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 {
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
background-color: #
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
background
|
| 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 |
-
|
| 77 |
-
border-
|
| 78 |
-
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
background-color: #0056b3;
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
}
|
| 96 |
</style>
|
| 97 |
</head>
|
| 98 |
<body>
|
| 99 |
<div class="container">
|
| 100 |
-
<h1
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 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 |
-
|
| 148 |
{% endif %}
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
<div class="schema-summary">
|
| 154 |
-
<
|
| 155 |
-
<p>{{ summary.description }}</p>
|
| 156 |
-
|
| 157 |
-
<h4>Main Tables and Columns</h4>
|
| 158 |
<ul>
|
| 159 |
{% for table, columns in summary.main_tables.items() %}
|
| 160 |
-
|
| 161 |
{% endfor %}
|
| 162 |
</ul>
|
| 163 |
-
|
| 164 |
-
{% if summary.relationships %}
|
| 165 |
-
<h4>Key Relationships</h4>
|
| 166 |
<ul>
|
| 167 |
-
{% for
|
| 168 |
-
|
| 169 |
{% endfor %}
|
| 170 |
</ul>
|
| 171 |
-
|
| 172 |
-
<
|
| 173 |
-
<p><
|
| 174 |
-
<p>{{ summary.suggestions.note }}</p>
|
| 175 |
-
{% if summary.suggestions.recommendations %}
|
| 176 |
<ul>
|
| 177 |
{% for rec in summary.suggestions.recommendations %}
|
| 178 |
-
|
| 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 |
-
|
| 192 |
-
<
|
| 193 |
-
|
| 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 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
<pre class="bg-light p-3 rounded">{{ query }}</pre>
|
| 208 |
</div>
|
| 209 |
-
</div>
|
| 210 |
{% endif %}
|
| 211 |
-
|
| 212 |
-
|
| 213 |
{% if results %}
|
| 214 |
-
|
| 215 |
-
<
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
<tr>
|
| 219 |
-
{% for key in results[0].keys() %}
|
| 220 |
<th>{{ key }}</th>
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
<tbody>
|
| 225 |
-
{% for row in results %}
|
| 226 |
<tr>
|
| 227 |
-
{% for
|
| 228 |
-
|
| 229 |
{% endfor %}
|
| 230 |
</tr>
|
| 231 |
-
|
| 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
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 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()">×</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>
|