Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,27 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
print("DEBUG: Files here:", os.listdir(os.getcwd()))
|
| 5 |
-
print("DEBUG: /app contains:", os.listdir("/app"))
|
| 6 |
-
print("DEBUG: Full tree under /app:", list(os.walk("/app")))
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 12 |
-
|
| 13 |
|
| 14 |
-
if
|
| 15 |
-
sys.path.insert(0,
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
from
|
| 21 |
-
from
|
|
|
|
| 22 |
|
|
|
|
| 23 |
app = FastAPI(title="Omniscient Backend API")
|
| 24 |
|
| 25 |
# ─── Health Check ─────────────────────────────────────────────
|
|
@@ -41,21 +43,25 @@ async def summarize(file: UploadFile):
|
|
| 41 |
@app.post("/analyze-log")
|
| 42 |
async def analyze_log(file: UploadFile, query: str = Form(None)):
|
| 43 |
try:
|
| 44 |
-
|
| 45 |
-
normalized = [normalize_log_line(line) for line in
|
|
|
|
| 46 |
result = {
|
| 47 |
"total_lines": len(normalized),
|
| 48 |
"unique_entries": len(set(normalized)),
|
| 49 |
"preview": normalized[:50],
|
| 50 |
}
|
|
|
|
| 51 |
if query:
|
| 52 |
matches = keyword_search("\n".join(normalized), query)
|
| 53 |
result["matches"] = matches[:50]
|
|
|
|
| 54 |
return {"file": file.filename, "analysis": result}
|
|
|
|
| 55 |
except Exception as e:
|
| 56 |
return {"error": str(e)}
|
| 57 |
|
| 58 |
-
# ─── Script Documentation Generator
|
| 59 |
@app.post("/generate-doc")
|
| 60 |
async def gen_doc(file: UploadFile):
|
| 61 |
try:
|
|
|
|
| 1 |
+
# ─────────────────────────────────────────────────────────────
|
| 2 |
+
# FIXED APP.PY – PROPERLY RESOLVES UTILS IMPORTS ON HF SPACES
|
| 3 |
+
# ─────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
from fastapi import FastAPI, UploadFile, Form
|
| 8 |
+
from fastapi.responses import JSONResponse
|
| 9 |
|
| 10 |
+
# ─── Ensure /app/utils is visible as top-level modules ─────────
|
|
|
|
| 11 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 12 |
+
UTILS_DIR = os.path.join(BASE_DIR, "utils")
|
| 13 |
|
| 14 |
+
if UTILS_DIR not in sys.path:
|
| 15 |
+
sys.path.insert(0, UTILS_DIR)
|
| 16 |
|
| 17 |
+
print("DEBUG: Using UTILS_DIR:", UTILS_DIR)
|
| 18 |
+
|
| 19 |
+
# ─── Correct imports based on actual filesystem ───────────────
|
| 20 |
+
from summarizer import summarize_text
|
| 21 |
+
from file_utils import normalize_log_line, keyword_search
|
| 22 |
+
from docgen import generate_doc
|
| 23 |
|
| 24 |
+
# ─── FastAPI App Init ─────────────────────────────────────────
|
| 25 |
app = FastAPI(title="Omniscient Backend API")
|
| 26 |
|
| 27 |
# ─── Health Check ─────────────────────────────────────────────
|
|
|
|
| 43 |
@app.post("/analyze-log")
|
| 44 |
async def analyze_log(file: UploadFile, query: str = Form(None)):
|
| 45 |
try:
|
| 46 |
+
raw = (await file.read()).decode("utf-8", errors="ignore")
|
| 47 |
+
normalized = [normalize_log_line(line) for line in raw.splitlines()]
|
| 48 |
+
|
| 49 |
result = {
|
| 50 |
"total_lines": len(normalized),
|
| 51 |
"unique_entries": len(set(normalized)),
|
| 52 |
"preview": normalized[:50],
|
| 53 |
}
|
| 54 |
+
|
| 55 |
if query:
|
| 56 |
matches = keyword_search("\n".join(normalized), query)
|
| 57 |
result["matches"] = matches[:50]
|
| 58 |
+
|
| 59 |
return {"file": file.filename, "analysis": result}
|
| 60 |
+
|
| 61 |
except Exception as e:
|
| 62 |
return {"error": str(e)}
|
| 63 |
|
| 64 |
+
# ─── Script Documentation Generator ───────────────────────────
|
| 65 |
@app.post("/generate-doc")
|
| 66 |
async def gen_doc(file: UploadFile):
|
| 67 |
try:
|