AshenH commited on
Commit
a2fcbc9
·
verified ·
1 Parent(s): 1470e7a

Update tools/report_tool.py

Browse files
Files changed (1) hide show
  1. tools/report_tool.py +1 -20
tools/report_tool.py CHANGED
@@ -13,13 +13,8 @@ class ReportTool:
13
  def __init__(self, cfg: AppConfig, tracer: Tracer):
14
  self.cfg = cfg
15
  self.tracer = tracer
16
-
17
- # Resolve the /space/templates directory reliably whether run as script or module
18
- templates_dir = os.path.abspath(
19
- os.path.join(os.path.dirname(__file__), "..", "templates")
20
- )
21
  self.env = Environment(loader=FileSystemLoader(templates_dir), autoescape=False)
22
- self.templates_dir = templates_dir # keep for any future file refs
23
 
24
  def render_and_save(
25
  self,
@@ -29,12 +24,7 @@ class ReportTool:
29
  explain_images: Dict[str, str],
30
  plan: Dict[str, Any],
31
  ) -> str:
32
- """
33
- Render a simple HTML report from the Markdown-like template, then save it next to app.py.
34
- Returns the relative path to the generated HTML file.
35
- """
36
  tmpl = self.env.get_template("report_template.md")
37
-
38
  html_body = tmpl.render(
39
  user_query=user_query,
40
  plan=plan,
@@ -42,23 +32,14 @@ class ReportTool:
42
  predict_preview=predict_preview.to_markdown(index=False) if isinstance(predict_preview, pd.DataFrame) else "",
43
  explain_images=explain_images or {},
44
  )
45
-
46
- # Name the output in the working dir (HF Spaces serves from cwd)
47
  out_name = f"report_{pd.Timestamp.utcnow().strftime('%Y%m%d_%H%M%S')}.html"
48
  out_path = os.path.abspath(os.path.join(os.getcwd(), out_name))
49
-
50
- # Link stylesheet relative to the app working dir (matches scaffold layout)
51
  css_link = "templates/report_styles.css"
52
  html = f'<link rel="stylesheet" href="{css_link}">\n' + html_body
53
-
54
  with open(out_path, "w", encoding="utf-8") as f:
55
  f.write(html)
56
-
57
- # trace
58
  try:
59
  self.tracer.trace_event("report", {"path": out_name})
60
  except Exception:
61
  pass
62
-
63
- # Return a relative path so Gradio can offer it as a download if needed
64
  return out_name
 
13
  def __init__(self, cfg: AppConfig, tracer: Tracer):
14
  self.cfg = cfg
15
  self.tracer = tracer
16
+ templates_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "templates"))
 
 
 
 
17
  self.env = Environment(loader=FileSystemLoader(templates_dir), autoescape=False)
 
18
 
19
  def render_and_save(
20
  self,
 
24
  explain_images: Dict[str, str],
25
  plan: Dict[str, Any],
26
  ) -> str:
 
 
 
 
27
  tmpl = self.env.get_template("report_template.md")
 
28
  html_body = tmpl.render(
29
  user_query=user_query,
30
  plan=plan,
 
32
  predict_preview=predict_preview.to_markdown(index=False) if isinstance(predict_preview, pd.DataFrame) else "",
33
  explain_images=explain_images or {},
34
  )
 
 
35
  out_name = f"report_{pd.Timestamp.utcnow().strftime('%Y%m%d_%H%M%S')}.html"
36
  out_path = os.path.abspath(os.path.join(os.getcwd(), out_name))
 
 
37
  css_link = "templates/report_styles.css"
38
  html = f'<link rel="stylesheet" href="{css_link}">\n' + html_body
 
39
  with open(out_path, "w", encoding="utf-8") as f:
40
  f.write(html)
 
 
41
  try:
42
  self.tracer.trace_event("report", {"path": out_name})
43
  except Exception:
44
  pass
 
 
45
  return out_name