Spaces:
Sleeping
Sleeping
Commit
·
652ea96
1
Parent(s):
b3f44e8
add
Browse files- .gitignore +2 -1
- app.py +18 -9
.gitignore
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
__pycache__/*
|
|
|
|
|
|
| 1 |
+
__pycache__/*
|
| 2 |
+
.venv/*
|
app.py
CHANGED
|
@@ -57,13 +57,14 @@ def analyze_logs(logs: str, source: str, use_retrieval: bool, use_nli: bool, ver
|
|
| 57 |
verification_rows = [
|
| 58 |
[v["hypothesis"], v["label"], round(v["score"], 3)] for v in res.verification
|
| 59 |
]
|
|
|
|
| 60 |
return (
|
| 61 |
format_incident_section(res),
|
| 62 |
res.explanation,
|
| 63 |
format_cause_section(res),
|
| 64 |
retrieval_rows,
|
| 65 |
verification_rows,
|
| 66 |
-
|
| 67 |
"Analysis completed.",
|
| 68 |
)
|
| 69 |
|
|
@@ -71,15 +72,19 @@ def analyze_logs(logs: str, source: str, use_retrieval: bool, use_nli: bool, ver
|
|
| 71 |
def ticket_template(state: Optional[Dict[str, Any]], logs: str) -> str:
|
| 72 |
if not state:
|
| 73 |
return "Run analysis first."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
clipped_logs = truncate_logs(logs, head_lines=30, tail_lines=10, max_lines=60)
|
| 75 |
-
checks =
|
| 76 |
checks_md = "\n".join(f"- {c}" for c in checks)
|
| 77 |
-
summary = f"{
|
| 78 |
template = (
|
| 79 |
f"Summary:\n{summary}\n\n"
|
| 80 |
f"Steps to reproduce:\n- Describe sequence leading to error (fill in).\n- Attach failing request/sample data.\n\n"
|
| 81 |
f"Expected:\n- Service handles request successfully.\n\n"
|
| 82 |
-
f"Actual:\n- {
|
| 83 |
f"Checks performed / next steps:\n{checks_md}\n\n"
|
| 84 |
f"Logs snippet:\n{clipped_logs}\n"
|
| 85 |
)
|
|
@@ -89,8 +94,8 @@ def ticket_template(state: Optional[Dict[str, Any]], logs: str) -> str:
|
|
| 89 |
def export_json(state: Optional[Dict[str, Any]]):
|
| 90 |
if not state:
|
| 91 |
return None
|
| 92 |
-
# If state
|
| 93 |
-
data = json.dumps(state, ensure_ascii=False, indent=2)
|
| 94 |
tmp = tempfile.NamedTemporaryFile("w", delete=False, suffix=".json", encoding="utf-8")
|
| 95 |
tmp.write(data)
|
| 96 |
tmp.flush()
|
|
@@ -100,7 +105,7 @@ def export_json(state: Optional[Dict[str, Any]]):
|
|
| 100 |
|
| 101 |
with gr.Blocks(title="Log Compiler App") as demo:
|
| 102 |
gr.Markdown("# Log Compiler App\nPaste logs/stacktrace to get incident classification, explanations, and runbook suggestions.")
|
| 103 |
-
state = gr.State()
|
| 104 |
|
| 105 |
with gr.Row():
|
| 106 |
with gr.Column(scale=1):
|
|
@@ -160,7 +165,11 @@ with gr.Blocks(title="Log Compiler App") as demo:
|
|
| 160 |
|
| 161 |
|
| 162 |
if __name__ == "__main__":
|
| 163 |
-
# Force share=True by default to avoid localhost access issues (HF Spaces/proxies).
|
| 164 |
share_env = os.getenv("GRADIO_SHARE")
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
demo.launch(server_name="0.0.0.0", share=share_flag)
|
|
|
|
| 57 |
verification_rows = [
|
| 58 |
[v["hypothesis"], v["label"], round(v["score"], 3)] for v in res.verification
|
| 59 |
]
|
| 60 |
+
state_payload = serialize_result(res)
|
| 61 |
return (
|
| 62 |
format_incident_section(res),
|
| 63 |
res.explanation,
|
| 64 |
format_cause_section(res),
|
| 65 |
retrieval_rows,
|
| 66 |
verification_rows,
|
| 67 |
+
state_payload,
|
| 68 |
"Analysis completed.",
|
| 69 |
)
|
| 70 |
|
|
|
|
| 72 |
def ticket_template(state: Optional[Dict[str, Any]], logs: str) -> str:
|
| 73 |
if not state:
|
| 74 |
return "Run analysis first."
|
| 75 |
+
try:
|
| 76 |
+
parsed = json.loads(state) if isinstance(state, str) else state
|
| 77 |
+
except Exception:
|
| 78 |
+
return "State corrupted. Re-run analysis."
|
| 79 |
clipped_logs = truncate_logs(logs, head_lines=30, tail_lines=10, max_lines=60)
|
| 80 |
+
checks = parsed.get("checks") or []
|
| 81 |
checks_md = "\n".join(f"- {c}" for c in checks)
|
| 82 |
+
summary = f"{parsed.get('incident_label','?')} — {parsed.get('explanation','')[:180]}"
|
| 83 |
template = (
|
| 84 |
f"Summary:\n{summary}\n\n"
|
| 85 |
f"Steps to reproduce:\n- Describe sequence leading to error (fill in).\n- Attach failing request/sample data.\n\n"
|
| 86 |
f"Expected:\n- Service handles request successfully.\n\n"
|
| 87 |
+
f"Actual:\n- {parsed.get('likely_cause','')}\n\n"
|
| 88 |
f"Checks performed / next steps:\n{checks_md}\n\n"
|
| 89 |
f"Logs snippet:\n{clipped_logs}\n"
|
| 90 |
)
|
|
|
|
| 94 |
def export_json(state: Optional[Dict[str, Any]]):
|
| 95 |
if not state:
|
| 96 |
return None
|
| 97 |
+
# If state is dict, dump; if already JSON string, use as-is.
|
| 98 |
+
data = json.dumps(state, ensure_ascii=False, indent=2) if isinstance(state, dict) else state
|
| 99 |
tmp = tempfile.NamedTemporaryFile("w", delete=False, suffix=".json", encoding="utf-8")
|
| 100 |
tmp.write(data)
|
| 101 |
tmp.flush()
|
|
|
|
| 105 |
|
| 106 |
with gr.Blocks(title="Log Compiler App") as demo:
|
| 107 |
gr.Markdown("# Log Compiler App\nPaste logs/stacktrace to get incident classification, explanations, and runbook suggestions.")
|
| 108 |
+
state = gr.State("")
|
| 109 |
|
| 110 |
with gr.Row():
|
| 111 |
with gr.Column(scale=1):
|
|
|
|
| 165 |
|
| 166 |
|
| 167 |
if __name__ == "__main__":
|
|
|
|
| 168 |
share_env = os.getenv("GRADIO_SHARE")
|
| 169 |
+
in_hf_space = bool(os.getenv("SPACE_ID") or os.getenv("HF_SPACE"))
|
| 170 |
+
# In HF Spaces share must be False; locally set GRADIO_SHARE=1 to force.
|
| 171 |
+
if in_hf_space:
|
| 172 |
+
share_flag = False
|
| 173 |
+
else:
|
| 174 |
+
share_flag = True if share_env is None else share_env.lower() in ("1", "true", "yes")
|
| 175 |
demo.launch(server_name="0.0.0.0", share=share_flag)
|