Spaces:
Runtime error
Runtime error
File size: 3,245 Bytes
a00cdf4 ebef6e3 a00cdf4 ebef6e3 a00cdf4 2a5208d a00cdf4 2a5208d a00cdf4 2a5208d a00cdf4 ca88fa5 a00cdf4 ca88fa5 0de71f7 ca88fa5 0de71f7 ca88fa5 a00cdf4 ca88fa5 a00cdf4 ca88fa5 a00cdf4 ca88fa5 a00cdf4 ca88fa5 ce0124c a00cdf4 ca88fa5 0de71f7 ca88fa5 ce0124c ca88fa5 |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# ─────────────────────────────────────────────────────────────
# FIXED APP.PY – PROPERLY RESOLVES UTILS IMPORTS ON HF SPACES
# ─────────────────────────────────────────────────────────────
import os
import sys
from fastapi import FastAPI, UploadFile, Form
from fastapi.responses import JSONResponse
# ─── Ensure /app/utils is visible as top-level modules ─────────
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
UTILS_DIR = os.path.join(BASE_DIR, "utils")
if UTILS_DIR not in sys.path:
sys.path.insert(0, UTILS_DIR)
print("DEBUG: Using UTILS_DIR:", UTILS_DIR)
# ─── Correct imports based on actual filesystem ───────────────
from summarizer import summarize_text
from file_utils import normalize_log_line, keyword_search
from docgen import generate_doc
# ─── FastAPI App Init ─────────────────────────────────────────
app = FastAPI(title="Omniscient Backend API")
# ─── Health Check ─────────────────────────────────────────────
@app.get("/health")
def health():
return JSONResponse({"ok": True, "message": "Omniscient backend alive"})
# ─── File Summarization ───────────────────────────────────────
@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)}
# ─── Log Normalization & Search ───────────────────────────────
@app.post("/analyze-log")
async def analyze_log(file: UploadFile, query: str = Form(None)):
try:
raw = (await file.read()).decode("utf-8", errors="ignore")
normalized = [normalize_log_line(line) for line in raw.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)}
# ─── Script Documentation Generator ───────────────────────────
@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)}
|