Update app.py
Browse files
app.py
CHANGED
|
@@ -5,16 +5,20 @@ Overthinker — Gradio.Server Backend with SQLite Session Isolation + HF Trace U
|
|
| 5 |
"""
|
| 6 |
|
| 7 |
import os
|
|
|
|
| 8 |
import json
|
| 9 |
import uuid
|
| 10 |
import sqlite3
|
|
|
|
|
|
|
| 11 |
from pathlib import Path
|
| 12 |
from typing import Optional, Dict, List, Any
|
| 13 |
|
| 14 |
from gradio import Server
|
| 15 |
from fastapi import HTTPException
|
| 16 |
from starlette.responses import HTMLResponse, PlainTextResponse
|
| 17 |
-
|
|
|
|
| 18 |
# ---------------------------------------------------------------------------
|
| 19 |
# Application Setup
|
| 20 |
# ---------------------------------------------------------------------------
|
|
@@ -297,6 +301,7 @@ def call_api(prompt: str, system_prompt: str = "You are a helpful assistant that
|
|
| 297 |
'Authorization': f'Bearer {OPENROUTER_API_KEY}',
|
| 298 |
'Content-Type': 'application/json',
|
| 299 |
'HTTP-Referer': 'http://localhost:7860',
|
|
|
|
| 300 |
}
|
| 301 |
data = {
|
| 302 |
'model': DEFAULT_MODEL,
|
|
@@ -326,7 +331,6 @@ def parse_json_response(text: str) -> Optional[dict]:
|
|
| 326 |
if not text:
|
| 327 |
return None
|
| 328 |
text = text.strip()
|
| 329 |
-
import re
|
| 330 |
text = re.sub(r'```json\s*', '', text)
|
| 331 |
text = re.sub(r'```\s*', '', text)
|
| 332 |
text = text.strip()
|
|
@@ -503,8 +507,7 @@ async def upload_trace(request: dict):
|
|
| 503 |
raise HTTPException(status_code=404, detail="No tree found for this session.")
|
| 504 |
|
| 505 |
try:
|
| 506 |
-
|
| 507 |
-
import pandas as pd
|
| 508 |
|
| 509 |
row = {
|
| 510 |
'session_id': session_id,
|
|
@@ -575,7 +578,6 @@ async def export_path_md(request: dict):
|
|
| 575 |
# Launch
|
| 576 |
# ---------------------------------------------------------------------------
|
| 577 |
if __name__ == "__main__":
|
| 578 |
-
import requests # needed for sync calls inside async routes
|
| 579 |
print(f"\U0001f9e0 Overthinker — SQLite Session Mode + HF Trace Upload on port {PORT}")
|
| 580 |
print(f"\U0001f916 Model: {DEFAULT_MODEL}")
|
| 581 |
print(f"\U0001f310 Open http://localhost:{PORT} in your browser")
|
|
|
|
| 5 |
"""
|
| 6 |
|
| 7 |
import os
|
| 8 |
+
import re
|
| 9 |
import json
|
| 10 |
import uuid
|
| 11 |
import sqlite3
|
| 12 |
+
import requests
|
| 13 |
+
|
| 14 |
from pathlib import Path
|
| 15 |
from typing import Optional, Dict, List, Any
|
| 16 |
|
| 17 |
from gradio import Server
|
| 18 |
from fastapi import HTTPException
|
| 19 |
from starlette.responses import HTMLResponse, PlainTextResponse
|
| 20 |
+
from datasets import Dataset, concatenate_datasets, load_dataset
|
| 21 |
+
import pandas as pd
|
| 22 |
# ---------------------------------------------------------------------------
|
| 23 |
# Application Setup
|
| 24 |
# ---------------------------------------------------------------------------
|
|
|
|
| 301 |
'Authorization': f'Bearer {OPENROUTER_API_KEY}',
|
| 302 |
'Content-Type': 'application/json',
|
| 303 |
'HTTP-Referer': 'http://localhost:7860',
|
| 304 |
+
'X-Title': 'Overthinker'
|
| 305 |
}
|
| 306 |
data = {
|
| 307 |
'model': DEFAULT_MODEL,
|
|
|
|
| 331 |
if not text:
|
| 332 |
return None
|
| 333 |
text = text.strip()
|
|
|
|
| 334 |
text = re.sub(r'```json\s*', '', text)
|
| 335 |
text = re.sub(r'```\s*', '', text)
|
| 336 |
text = text.strip()
|
|
|
|
| 507 |
raise HTTPException(status_code=404, detail="No tree found for this session.")
|
| 508 |
|
| 509 |
try:
|
| 510 |
+
|
|
|
|
| 511 |
|
| 512 |
row = {
|
| 513 |
'session_id': session_id,
|
|
|
|
| 578 |
# Launch
|
| 579 |
# ---------------------------------------------------------------------------
|
| 580 |
if __name__ == "__main__":
|
|
|
|
| 581 |
print(f"\U0001f9e0 Overthinker — SQLite Session Mode + HF Trace Upload on port {PORT}")
|
| 582 |
print(f"\U0001f916 Model: {DEFAULT_MODEL}")
|
| 583 |
print(f"\U0001f310 Open http://localhost:{PORT} in your browser")
|