File size: 1,931 Bytes
b4de735
7a57180
0a1f9c3
b4de735
 
 
 
 
 
 
 
 
0a1f9c3
 
 
 
 
 
7a57180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
import sys, os
from fastapi import FastAPI, UploadFile, Form
from fastapi.responses import JSONResponse

# Ensure omniscientframework/ is importable
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
if ROOT not in sys.path:
    sys.path.insert(0, ROOT)

from omniscientframework.utils.summarizer import summarize_text
from omniscientframework.utils.file_utils import normalize_log_line, keyword_search
from omniscientframework.utils.docgen import generate_doc

app = FastAPI(title="Omniscient Backend API")

@app.get("/health")
def health():
    return JSONResponse({"ok": True, "message": "Omniscient backend alive"})

@app.post("/summarize")
async def summarize(file: UploadFile):
    try:
        content = (await file.read()).decode("utf-8", errors="ignore")
        summary = summarize_text(content)
        return {"file": file.filename, "summary": summary}
    except Exception as e:
        return {"error": str(e)}

@app.post("/analyze-log")
async def analyze_log(file: UploadFile, query: str = Form(None)):
    try:
        content = (await file.read()).decode("utf-8", errors="ignore")
        normalized = [normalize_log_line(line) for line in content.splitlines()]
        result = {
            "total_lines": len(normalized),
            "unique_entries": len(set(normalized)),
            "preview": normalized[:50],
        }
        if query:
            matches = keyword_search("\n".join(normalized), query)
            result["matches"] = matches[:50]
        return {"file": file.filename, "analysis": result}
    except Exception as e:
        return {"error": str(e)}

@app.post("/generate-doc")
async def gen_doc(file: UploadFile):
    try:
        content = (await file.read()).decode("utf-8", errors="ignore")
        doc = generate_doc(file.filename, "uploaded", content)
        return {"file": file.filename, "doc": doc}
    except Exception as e:
        return {"error": str(e)}