Spaces:
Sleeping

Corin1998 commited on
Commit
0f9055f
·
verified ·
1 Parent(s): da68aed

Update ui/dash.py

Browse files
Files changed (1) hide show
  1. ui/dash.py +9 -82
ui/dash.py CHANGED
@@ -1,88 +1,15 @@
1
  # ui/dash.py
2
- from __future__ import annotations
3
- import json, sys, pkgutil
4
- import pandas as pd
5
  import gradio as gr
6
 
7
- def _theme():
8
- # 余計な拡張なしの素のテーマ(古い Gradio でも安全)
9
- return gr.themes.Soft()
10
-
11
- def _env_diag_json() -> str:
12
- info = {
13
- "python": sys.version,
14
- "packages": sorted([
15
- m.name for m in pkgutil.iter_modules()
16
- if m.name.startswith(("gradio","pdf","pandas","openai"))
17
- ]),
18
- }
19
- return json.dumps(info, ensure_ascii=False, indent=2)
20
-
21
- def _run(pdf_path, unit_code, company, industry, use_llm, api_key):
22
- try:
23
- from app.services.pipeline import run_full_pipeline
24
- out = run_full_pipeline(
25
- pdf_file=pdf_path, # File は "filepath" で受け取る
26
- unit=unit_code,
27
- company_name=(company or "").strip() or None,
28
- industry=(industry or "").strip() or None,
29
- use_llm=bool(use_llm),
30
- openai_api_key=(api_key or "").strip() or None,
31
- )
32
- # out: (summary_md, kpis_df, ratios_df, scores_df)
33
- return out
34
- except Exception as e:
35
- import traceback
36
- tb = traceback.format_exc()
37
- return (f"解析で例外が発生しました:\n```\n{tb}\n```",
38
- pd.DataFrame(), pd.DataFrame(), pd.DataFrame())
39
-
40
  def build_interface() -> gr.Blocks:
41
- with gr.Blocks(title="Company Health Score (LLM)", theme=_theme()) as demo:
42
- gr.Markdown("# 企業スコア(PDF→LLM/正規表現→指標→スコア)")
43
-
 
44
  with gr.Row():
45
- pdf = gr.File(label="決算書PDF", file_types=[".pdf"],
46
- type="filepath", file_count="single")
47
- company = gr.Textbox(label="会社名(任意)", placeholder="例:株式会社〇〇")
48
- unit = gr.Radio(
49
- label="金額の単位",
50
- value="AUTO",
51
- choices=["AUTO","JPY","KJPY","MMJPY","OKJPY"],
52
- )
53
- industry = gr.Dropdown(
54
- label="業種(任意)",
55
- choices=["","製造","小売","サービス","IT","建設","運輸","不動産","金融","医療","教育"],
56
- value=""
57
- )
58
-
59
- with gr.Row():
60
- use_llm = gr.Checkbox(label="LLMで読み取る(OpenAI APIキー必須)", value=True)
61
- api_key = gr.Textbox(label="OpenAI API Key", type="password",
62
- placeholder="sk-...(未入力なら正規表現フォールバック)")
63
-
64
- run_btn = gr.Button("解析する", variant="primary")
65
-
66
- with gr.Tab("結果サマリ"):
67
- summary = gr.Markdown("ここにサマリが表示されます。")
68
-
69
- with gr.Tab("KPI / 主要数値"):
70
- kpis = gr.Dataframe(interactive=False)
71
-
72
- with gr.Tab("財務比率"):
73
- ratios = gr.Dataframe(interactive=False)
74
-
75
- with gr.Tab("スコア"):
76
- scores = gr.Dataframe(interactive=False)
77
-
78
- with gr.Accordion("起動診断", open=False):
79
- # gr.JSON はバージョン差で OpenAPI 生成が失敗することがあるため Code に
80
- gr.Code(value=_env_diag_json(), language="json", label="環境")
81
-
82
- run_btn.click(
83
- _run,
84
- inputs=[pdf, unit, company, industry, use_llm, api_key],
85
- outputs=[summary, kpis, ratios, scores],
86
- )
87
-
88
  return demo
 
1
  # ui/dash.py
 
 
 
2
  import gradio as gr
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  def build_interface() -> gr.Blocks:
5
+ # Gradio v4 は theme 引数のショートカットが厳密: 無難なデフォルト使う
6
+ demo = gr.Blocks(title="Company Health Score - Minimal")
7
+ with demo:
8
+ gr.Markdown("## Minimal boot\n起動確認用の最小UI(ここが表示されれば初期化OK)")
9
  with gr.Row():
10
+ inp = gr.Textbox(label="Ping")
11
+ out = gr.Textbox(label="Pong", interactive=False)
12
+ def ping(x: str) -> str:
13
+ return f"pong: {x}"
14
+ gr.Button("Send").click(ping, inp, out)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  return demo