Spaces:
Sleeping
Sleeping
Commit
·
b3f44e8
1
Parent(s):
7cf5951
add
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import tempfile
|
|
|
|
| 4 |
from typing import Any, Dict, List, Optional
|
| 5 |
|
| 6 |
import gradio as gr
|
|
@@ -62,32 +63,34 @@ def analyze_logs(logs: str, source: str, use_retrieval: bool, use_nli: bool, ver
|
|
| 62 |
format_cause_section(res),
|
| 63 |
retrieval_rows,
|
| 64 |
verification_rows,
|
| 65 |
-
res,
|
| 66 |
"Analysis completed.",
|
| 67 |
)
|
| 68 |
|
| 69 |
|
| 70 |
-
def ticket_template(state: Optional[
|
| 71 |
-
if state
|
| 72 |
return "Run analysis first."
|
| 73 |
clipped_logs = truncate_logs(logs, head_lines=30, tail_lines=10, max_lines=60)
|
| 74 |
-
|
| 75 |
-
|
|
|
|
| 76 |
template = (
|
| 77 |
f"Summary:\n{summary}\n\n"
|
| 78 |
f"Steps to reproduce:\n- Describe sequence leading to error (fill in).\n- Attach failing request/sample data.\n\n"
|
| 79 |
f"Expected:\n- Service handles request successfully.\n\n"
|
| 80 |
-
f"Actual:\n- {state.likely_cause}\n\n"
|
| 81 |
f"Checks performed / next steps:\n{checks_md}\n\n"
|
| 82 |
f"Logs snippet:\n{clipped_logs}\n"
|
| 83 |
)
|
| 84 |
return template
|
| 85 |
|
| 86 |
|
| 87 |
-
def export_json(state: Optional[
|
| 88 |
-
if state
|
| 89 |
return None
|
| 90 |
-
|
|
|
|
| 91 |
tmp = tempfile.NamedTemporaryFile("w", delete=False, suffix=".json", encoding="utf-8")
|
| 92 |
tmp.write(data)
|
| 93 |
tmp.flush()
|
|
@@ -157,11 +160,7 @@ with gr.Blocks(title="Log Compiler App") as demo:
|
|
| 157 |
|
| 158 |
|
| 159 |
if __name__ == "__main__":
|
|
|
|
| 160 |
share_env = os.getenv("GRADIO_SHARE")
|
| 161 |
-
|
| 162 |
-
# In Spaces we do not need share=True; locally default to share to bypass localhost issues.
|
| 163 |
-
if in_hf_space:
|
| 164 |
-
share_flag = False
|
| 165 |
-
else:
|
| 166 |
-
share_flag = True if share_env is None else share_env.lower() in ("1", "true", "yes")
|
| 167 |
demo.launch(server_name="0.0.0.0", share=share_flag)
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import tempfile
|
| 4 |
+
from dataclasses import asdict
|
| 5 |
from typing import Any, Dict, List, Optional
|
| 6 |
|
| 7 |
import gradio as gr
|
|
|
|
| 63 |
format_cause_section(res),
|
| 64 |
retrieval_rows,
|
| 65 |
verification_rows,
|
| 66 |
+
asdict(res),
|
| 67 |
"Analysis completed.",
|
| 68 |
)
|
| 69 |
|
| 70 |
|
| 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 = state.get("checks") or []
|
| 76 |
+
checks_md = "\n".join(f"- {c}" for c in checks)
|
| 77 |
+
summary = f"{state.get('incident_label','?')} — {state.get('explanation','')[:180]}"
|
| 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- {state.get('likely_cause','')}\n\n"
|
| 83 |
f"Checks performed / next steps:\n{checks_md}\n\n"
|
| 84 |
f"Logs snippet:\n{clipped_logs}\n"
|
| 85 |
)
|
| 86 |
return template
|
| 87 |
|
| 88 |
|
| 89 |
+
def export_json(state: Optional[Dict[str, Any]]):
|
| 90 |
+
if not state:
|
| 91 |
return None
|
| 92 |
+
# If state already dict, dump; otherwise try serialize_result.
|
| 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()
|
|
|
|
| 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 |
+
share_flag = True if share_env is None else share_env.lower() in ("1", "true", "yes")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
demo.launch(server_name="0.0.0.0", share=share_flag)
|