Kogann commited on
Commit
a727a52
·
verified ·
1 Parent(s): 06eab3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -331,7 +331,7 @@ def run_code(code: str, df: pd.DataFrame) -> dict:
331
  for i, num in enumerate(plt.get_fignums(), start=1):
332
  fig = plt.figure(num)
333
  if fig.get_axes():
334
- fig.savefig(f"{PLOTS_DIR}/figure_{i}.png")
335
  plt.close("all")
336
  plt.savefig, sns.heatmap, sns.histplot = (
337
  real["savefig"], real["heatmap"], real["histplot"])
@@ -504,7 +504,7 @@ def embed_images(md: str) -> str:
504
 
505
 
506
  def report_to_pdf(report_md: str, plots: list, path: str = "eda_report.pdf") -> str:
507
- """Render the markdown report plus every figure to a single PDF."""
508
  from fpdf import FPDF
509
  from fpdf.enums import XPos, YPos
510
 
@@ -591,7 +591,7 @@ def build_report(df, res, name, instruction, dropped=None) -> tuple:
591
  *[l.strip() for l in take.splitlines() if l.strip().startswith(("-", "*"))][:3],
592
  ""]
593
 
594
- P += ["## Figures", ""]
595
  for p in res["plots"]:
596
  P += [f"**{os.path.basename(p)[:-4].replace('_', ' ')}**", "", f"![]({p})", ""]
597
 
@@ -660,7 +660,7 @@ def _pipeline(instruction: str, dataset: str):
660
  except Exception as e:
661
  pdf, pdf_note = None, f" (PDF unavailable: {type(e).__name__})"
662
 
663
- yield (f"Done — {status.lower()}, {len(plots)} figures.{pdf_note}",
664
  pdf, code, res["stdout"], plots,
665
  embed_images(report), ", ".join(flags) if flags else "none")
666
 
@@ -765,19 +765,21 @@ def reset_form():
765
  # Minimal CSS only. A full-height card and a hidden footer both interfered with
766
  # the height negotiation of the Spaces iframe.
767
  CSS = """
 
768
  .qs-card {border:1px solid var(--border-color-primary);
769
  border-radius:12px; padding:10px 12px;}
770
  """
771
 
772
- with gr.Blocks(title="EDA Agent", theme=gr.themes.Soft(), css=CSS) as demo:
773
  gr.Markdown(
774
- "# 📊 EDA Agent\n"
775
  "**Point it at any Hugging Face dataset. It writes its own analysis code, "
776
- "runs it, fixes it when it crashes, and hands back a report.**"
 
777
  )
778
  gr.Markdown(
779
  "Powered by `Qwen2.5-Coder-1.5B-Instruct`. The model writes **code and prose "
780
- "only** — every table, figure and “which is highest” lookup is computed in "
781
  "pandas, so the numbers in the report cannot be hallucinated. "
782
  "A built-in check flags any figure in the text that is missing from the data."
783
  )
@@ -808,7 +810,7 @@ with gr.Blocks(title="EDA Agent", theme=gr.themes.Soft(), css=CSS) as demo:
808
  )
809
 
810
  status = gr.Markdown()
811
- pdf_file = gr.File(label="⬇️ Full report as PDF (text, tables and every figure)")
812
 
813
  with gr.Tabs():
814
  with gr.Tab("📄 Report"):
@@ -817,8 +819,8 @@ with gr.Blocks(title="EDA Agent", theme=gr.themes.Soft(), css=CSS) as demo:
817
  interactive=False)
818
  # No fixed heights: a nested scroll region with nothing to scroll makes
819
  # Safari swallow the wheel event instead of passing it to the page.
820
- with gr.Tab("🖼️ Figures"):
821
- gallery = gr.Gallery(label="Figures", columns=2)
822
  with gr.Tab("🐍 Generated code"):
823
  code_box = gr.Code(language="python", label="Model-written analysis code")
824
  with gr.Tab("🖥️ Execution output"):
 
331
  for i, num in enumerate(plt.get_fignums(), start=1):
332
  fig = plt.figure(num)
333
  if fig.get_axes():
334
+ fig.savefig(f"{PLOTS_DIR}/plot_{i}.png")
335
  plt.close("all")
336
  plt.savefig, sns.heatmap, sns.histplot = (
337
  real["savefig"], real["heatmap"], real["histplot"])
 
504
 
505
 
506
  def report_to_pdf(report_md: str, plots: list, path: str = "eda_report.pdf") -> str:
507
+ """Render the markdown report plus every plot to a single PDF."""
508
  from fpdf import FPDF
509
  from fpdf.enums import XPos, YPos
510
 
 
591
  *[l.strip() for l in take.splitlines() if l.strip().startswith(("-", "*"))][:3],
592
  ""]
593
 
594
+ P += ["## Plots", ""]
595
  for p in res["plots"]:
596
  P += [f"**{os.path.basename(p)[:-4].replace('_', ' ')}**", "", f"![]({p})", ""]
597
 
 
660
  except Exception as e:
661
  pdf, pdf_note = None, f" (PDF unavailable: {type(e).__name__})"
662
 
663
+ yield (f"Done — {status.lower()}, {len(plots)} plots.{pdf_note}",
664
  pdf, code, res["stdout"], plots,
665
  embed_images(report), ", ".join(flags) if flags else "none")
666
 
 
765
  # Minimal CSS only. A full-height card and a hidden footer both interfered with
766
  # the height negotiation of the Spaces iframe.
767
  CSS = """
768
+ .hero {text-align:center;}
769
  .qs-card {border:1px solid var(--border-color-primary);
770
  border-radius:12px; padding:10px 12px;}
771
  """
772
 
773
+ with gr.Blocks(title="EDAgent", theme=gr.themes.Soft(), css=CSS) as demo:
774
  gr.Markdown(
775
+ "# 📊 EDAgent\n"
776
  "**Point it at any Hugging Face dataset. It writes its own analysis code, "
777
+ "runs it, fixes it when it crashes, and hands back a report.**",
778
+ elem_classes="hero",
779
  )
780
  gr.Markdown(
781
  "Powered by `Qwen2.5-Coder-1.5B-Instruct`. The model writes **code and prose "
782
+ "only** — every table, plot and “which is highest” lookup is computed in "
783
  "pandas, so the numbers in the report cannot be hallucinated. "
784
  "A built-in check flags any figure in the text that is missing from the data."
785
  )
 
810
  )
811
 
812
  status = gr.Markdown()
813
+ pdf_file = gr.File(label="⬇️ Full report as PDF (text, tables and every plot)")
814
 
815
  with gr.Tabs():
816
  with gr.Tab("📄 Report"):
 
819
  interactive=False)
820
  # No fixed heights: a nested scroll region with nothing to scroll makes
821
  # Safari swallow the wheel event instead of passing it to the page.
822
+ with gr.Tab("🖼️ Plots"):
823
+ gallery = gr.Gallery(label="Plots", columns=2)
824
  with gr.Tab("🐍 Generated code"):
825
  code_box = gr.Code(language="python", label="Model-written analysis code")
826
  with gr.Tab("🖥️ Execution output"):