Spaces:
Running
Running
Commit
·
8b5825a
1
Parent(s):
5fe33c9
Deploy Signal Generator app
Browse files
src/db/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (889 Bytes). View file
|
|
|
src/db/__pycache__/local_database.cpython-313.pyc
ADDED
|
Binary file (57.7 kB). View file
|
|
|
src/main.py
CHANGED
|
@@ -225,6 +225,110 @@ async def get_signals():
|
|
| 225 |
logger.error(f"Error fetching signals: {e}")
|
| 226 |
raise HTTPException(status_code=500, detail="Database error")
|
| 227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
@app.get("/", response_class=HTMLResponse)
|
| 229 |
async def root(request: Request):
|
| 230 |
"""
|
|
|
|
| 225 |
logger.error(f"Error fetching signals: {e}")
|
| 226 |
raise HTTPException(status_code=500, detail="Database error")
|
| 227 |
|
| 228 |
+
@app.post("/test-db", dependencies=[Depends(verify_api_secret)])
|
| 229 |
+
async def test_db_connection():
|
| 230 |
+
"""
|
| 231 |
+
Detailed database connection test
|
| 232 |
+
"""
|
| 233 |
+
results = {
|
| 234 |
+
"status": "failed",
|
| 235 |
+
"details": [],
|
| 236 |
+
"config": {}
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
try:
|
| 240 |
+
# Check env vars (redact password)
|
| 241 |
+
import os
|
| 242 |
+
results["config"] = {
|
| 243 |
+
"host": os.getenv('DB_HOST'),
|
| 244 |
+
"port": os.getenv('DB_PORT'),
|
| 245 |
+
"user": os.getenv('DB_USERNAME'),
|
| 246 |
+
"database": os.getenv('DB_DATABASE'),
|
| 247 |
+
"ssl_ca_set": bool(os.getenv('DB_SSL_CA'))
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
db = LocalDatabase()
|
| 251 |
+
conn = db._create_connection()
|
| 252 |
+
|
| 253 |
+
if conn and conn.is_connected():
|
| 254 |
+
results["status"] = "success"
|
| 255 |
+
results["details"].append("Connection successful")
|
| 256 |
+
results["details"].append(f"Server Info: {conn.get_server_info()}")
|
| 257 |
+
|
| 258 |
+
cursor = conn.cursor()
|
| 259 |
+
cursor.execute("SELECT VERSION()")
|
| 260 |
+
version = cursor.fetchone()
|
| 261 |
+
results["details"].append(f"DB Version: {version[0]}")
|
| 262 |
+
conn.close()
|
| 263 |
+
else:
|
| 264 |
+
results["details"].append("Connection object create but is_connected() returned False")
|
| 265 |
+
|
| 266 |
+
except Exception as e:
|
| 267 |
+
results["details"].append(f"Exception: {str(e)}")
|
| 268 |
+
import traceback
|
| 269 |
+
results["traceback"] = traceback.format_exc()
|
| 270 |
+
|
| 271 |
+
return results
|
| 272 |
+
|
| 273 |
+
@app.post("/test-ollama", dependencies=[Depends(verify_api_secret)])
|
| 274 |
+
async def test_ollama_connection():
|
| 275 |
+
"""
|
| 276 |
+
Test Ollama connectivity and model status
|
| 277 |
+
"""
|
| 278 |
+
import requests
|
| 279 |
+
results = {
|
| 280 |
+
"status": "failed",
|
| 281 |
+
"details": [],
|
| 282 |
+
"model_found": False
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
try:
|
| 286 |
+
# 1. Check if Service is Up
|
| 287 |
+
base_url = "http://localhost:11434"
|
| 288 |
+
try:
|
| 289 |
+
resp = requests.get(f"{base_url}/api/tags", timeout=5)
|
| 290 |
+
if resp.status_code == 200:
|
| 291 |
+
results["details"].append("Ollama Service is UP")
|
| 292 |
+
models = resp.json().get('models', [])
|
| 293 |
+
model_names = [m.get('name') for m in models]
|
| 294 |
+
results["details"].append(f"Available Models: {', '.join(model_names)}")
|
| 295 |
+
|
| 296 |
+
if any("llama3.1" in m for m in model_names):
|
| 297 |
+
results["model_found"] = True
|
| 298 |
+
else:
|
| 299 |
+
results["details"].append("WARNING: llama3.1 model not found in list!")
|
| 300 |
+
else:
|
| 301 |
+
results["details"].append(f"Service returned status {resp.status_code}")
|
| 302 |
+
return results
|
| 303 |
+
except Exception as e:
|
| 304 |
+
results["details"].append(f"Failed to connect to Ollama Service: {e}")
|
| 305 |
+
return results
|
| 306 |
+
|
| 307 |
+
# 2. Test Generation (if service is up)
|
| 308 |
+
if results["model_found"]:
|
| 309 |
+
try:
|
| 310 |
+
payload = {
|
| 311 |
+
"model": "llama3.1",
|
| 312 |
+
"prompt": "hi",
|
| 313 |
+
"stream": False
|
| 314 |
+
}
|
| 315 |
+
resp = requests.post(f"{base_url}/api/generate", json=payload, timeout=10)
|
| 316 |
+
if resp.status_code == 200:
|
| 317 |
+
ans = resp.json().get('response', '')
|
| 318 |
+
results["details"].append(f"Generation Test Pass: '{ans[:20]}...'")
|
| 319 |
+
results["status"] = "success"
|
| 320 |
+
else:
|
| 321 |
+
results["details"].append(f"Generation Failed: {resp.text}")
|
| 322 |
+
except Exception as e:
|
| 323 |
+
results["details"].append(f"Generation Error: {e}")
|
| 324 |
+
else:
|
| 325 |
+
results["details"].append("Skipping generation test as model not found.")
|
| 326 |
+
|
| 327 |
+
except Exception as e:
|
| 328 |
+
results["details"].append(f"Unexpected Error: {e}")
|
| 329 |
+
|
| 330 |
+
return results
|
| 331 |
+
|
| 332 |
@app.get("/", response_class=HTMLResponse)
|
| 333 |
async def root(request: Request):
|
| 334 |
"""
|
src/templates/index.html
CHANGED
|
@@ -188,9 +188,17 @@
|
|
| 188 |
<span style="color:var(--text-secondary)">Ollama</span>
|
| 189 |
<span id="ollamaStatus">Checking...</span>
|
| 190 |
</div>
|
| 191 |
-
<
|
| 192 |
-
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
</div>
|
| 195 |
</div>
|
| 196 |
|
|
@@ -347,6 +355,64 @@
|
|
| 347 |
alert('Failed to start analysis');
|
| 348 |
}
|
| 349 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
</script>
|
| 351 |
</body>
|
| 352 |
</html>
|
|
|
|
| 188 |
<span style="color:var(--text-secondary)">Ollama</span>
|
| 189 |
<span id="ollamaStatus">Checking...</span>
|
| 190 |
</div>
|
| 191 |
+
<div style="display: flex; gap: 0.5rem;">
|
| 192 |
+
<button class="btn btn-purple" onclick="runAnalysis()" style="flex: 1;">
|
| 193 |
+
Run Analysis
|
| 194 |
+
</button>
|
| 195 |
+
<button class="btn" onclick="testDb()" style="flex: 1; background: #475569;">
|
| 196 |
+
Test DB
|
| 197 |
+
</button>
|
| 198 |
+
<button class="btn" onclick="testOllama()" style="flex: 1; background: #ea580c;">
|
| 199 |
+
Test LLM
|
| 200 |
+
</button>
|
| 201 |
+
</div>
|
| 202 |
</div>
|
| 203 |
</div>
|
| 204 |
|
|
|
|
| 355 |
alert('Failed to start analysis');
|
| 356 |
}
|
| 357 |
}
|
| 358 |
+
|
| 359 |
+
async function testDb() {
|
| 360 |
+
const btn = event.target;
|
| 361 |
+
const ogText = btn.innerText;
|
| 362 |
+
btn.innerText = 'Testing...';
|
| 363 |
+
btn.disabled = true;
|
| 364 |
+
|
| 365 |
+
try {
|
| 366 |
+
const res = await fetch('/test-db', {
|
| 367 |
+
method: 'POST',
|
| 368 |
+
headers: { 'X-API-Secret': API_SECRET }
|
| 369 |
+
});
|
| 370 |
+
const data = await res.json();
|
| 371 |
+
|
| 372 |
+
let msg = `Status: ${data.status.toUpperCase()}\n\n`;
|
| 373 |
+
if (data.details) msg += data.details.join('\n');
|
| 374 |
+
if (data.config) msg += `\n\nHost: ${data.config.host}\nSSL Set: ${data.config.ssl_ca_set}`;
|
| 375 |
+
|
| 376 |
+
alert(msg);
|
| 377 |
+
|
| 378 |
+
// Refresh health check UI
|
| 379 |
+
checkHealth();
|
| 380 |
+
|
| 381 |
+
} catch (e) {
|
| 382 |
+
alert('Test request failed: ' + e);
|
| 383 |
+
} finally {
|
| 384 |
+
btn.innerText = ogText;
|
| 385 |
+
btn.disabled = false;
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
async function testOllama() {
|
| 390 |
+
const btn = event.target;
|
| 391 |
+
const ogText = btn.innerText;
|
| 392 |
+
btn.innerText = 'Testing...';
|
| 393 |
+
btn.disabled = true;
|
| 394 |
+
|
| 395 |
+
try {
|
| 396 |
+
const res = await fetch('/test-ollama', {
|
| 397 |
+
method: 'POST',
|
| 398 |
+
headers: { 'X-API-Secret': API_SECRET }
|
| 399 |
+
});
|
| 400 |
+
const data = await res.json();
|
| 401 |
+
|
| 402 |
+
let msg = `Status: ${data.status.toUpperCase()}\n\n`;
|
| 403 |
+
if (data.details) msg += data.details.join('\n');
|
| 404 |
+
|
| 405 |
+
alert(msg);
|
| 406 |
+
|
| 407 |
+
checkHealth();
|
| 408 |
+
|
| 409 |
+
} catch (e) {
|
| 410 |
+
alert('Test request failed: ' + e);
|
| 411 |
+
} finally {
|
| 412 |
+
btn.innerText = ogText;
|
| 413 |
+
btn.disabled = false;
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
</script>
|
| 417 |
</body>
|
| 418 |
</html>
|