Update ui/dash.py
Browse files- ui/dash.py +16 -9
ui/dash.py
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
import json, sys, pkgutil
|
| 3 |
import pandas as pd
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
def _theme():
|
| 7 |
-
#
|
| 8 |
return gr.themes.Soft()
|
| 9 |
|
| 10 |
def _env_diag_json() -> str:
|
| 11 |
info = {
|
| 12 |
"python": sys.version,
|
| 13 |
-
"packages": sorted([
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
return json.dumps(info, ensure_ascii=False, indent=2)
|
| 17 |
|
| 18 |
-
def _run(
|
| 19 |
try:
|
| 20 |
from app.services.pipeline import run_full_pipeline
|
| 21 |
out = run_full_pipeline(
|
| 22 |
-
pdf_file=
|
| 23 |
unit=unit_code,
|
| 24 |
company_name=(company or "").strip() or None,
|
| 25 |
industry=(industry or "").strip() or None,
|
|
@@ -39,13 +42,14 @@ def build_interface() -> gr.Blocks:
|
|
| 39 |
gr.Markdown("# 企業スコア(PDF→LLM/正規表現→指標→スコア)")
|
| 40 |
|
| 41 |
with gr.Row():
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
company = gr.Textbox(label="会社名(任意)", placeholder="例:株式会社〇〇")
|
| 44 |
unit = gr.Radio(
|
| 45 |
label="金額の単位",
|
| 46 |
value="AUTO",
|
| 47 |
choices=["AUTO","JPY","KJPY","MMJPY","OKJPY"],
|
| 48 |
-
info="AUTO=自動推定(LLMまたは推定)。数値の桁は最終的にこの単位で換算します。"
|
| 49 |
)
|
| 50 |
industry = gr.Dropdown(
|
| 51 |
label="業種(任意)",
|
|
@@ -55,7 +59,8 @@ def build_interface() -> gr.Blocks:
|
|
| 55 |
|
| 56 |
with gr.Row():
|
| 57 |
use_llm = gr.Checkbox(label="LLMで読み取る(OpenAI APIキー必須)", value=True)
|
| 58 |
-
api_key = gr.Textbox(label="OpenAI API Key", type="password",
|
|
|
|
| 59 |
|
| 60 |
run_btn = gr.Button("解析する", variant="primary")
|
| 61 |
|
|
@@ -72,13 +77,15 @@ def build_interface() -> gr.Blocks:
|
|
| 72 |
scores = gr.Dataframe(interactive=False)
|
| 73 |
|
| 74 |
with gr.Accordion("起動診断", open=False):
|
|
|
|
|
|
|
| 75 |
gr.Code(value=_env_diag_json(), language="json", label="環境")
|
| 76 |
|
|
|
|
| 77 |
run_btn.click(
|
| 78 |
_run,
|
| 79 |
inputs=[pdf, unit, company, industry, use_llm, api_key],
|
| 80 |
outputs=[summary, kpis, ratios, scores],
|
| 81 |
-
api_name="analyze"
|
| 82 |
)
|
| 83 |
|
| 84 |
return demo
|
|
|
|
| 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 |
+
# シンプルなテーマに固定(拡張しない)
|
| 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, # ここは文字列パスで受け取る
|
| 26 |
unit=unit_code,
|
| 27 |
company_name=(company or "").strip() or None,
|
| 28 |
industry=(industry or "").strip() or None,
|
|
|
|
| 42 |
gr.Markdown("# 企業スコア(PDF→LLM/正規表現→指標→スコア)")
|
| 43 |
|
| 44 |
with gr.Row():
|
| 45 |
+
# File は **パス文字列** で受け取り、単一ファイルに固定
|
| 46 |
+
pdf = gr.File(label="決算書PDF", file_types=[".pdf"],
|
| 47 |
+
type="filepath", file_count="single")
|
| 48 |
company = gr.Textbox(label="会社名(任意)", placeholder="例:株式会社〇〇")
|
| 49 |
unit = gr.Radio(
|
| 50 |
label="金額の単位",
|
| 51 |
value="AUTO",
|
| 52 |
choices=["AUTO","JPY","KJPY","MMJPY","OKJPY"],
|
|
|
|
| 53 |
)
|
| 54 |
industry = gr.Dropdown(
|
| 55 |
label="業種(任意)",
|
|
|
|
| 59 |
|
| 60 |
with gr.Row():
|
| 61 |
use_llm = gr.Checkbox(label="LLMで読み取る(OpenAI APIキー必須)", value=True)
|
| 62 |
+
api_key = gr.Textbox(label="OpenAI API Key", type="password",
|
| 63 |
+
placeholder="sk-...(未入力なら正規表現フォールバック)")
|
| 64 |
|
| 65 |
run_btn = gr.Button("解析する", variant="primary")
|
| 66 |
|
|
|
|
| 77 |
scores = gr.Dataframe(interactive=False)
|
| 78 |
|
| 79 |
with gr.Accordion("起動診断", open=False):
|
| 80 |
+
# JSON コンポーネントは API スキーマで additionalProperties=true を出す場合があり
|
| 81 |
+
# 500 の原因になることがあるため、Code(Text)で表示します
|
| 82 |
gr.Code(value=_env_diag_json(), language="json", label="環境")
|
| 83 |
|
| 84 |
+
# api_name を付けると OpenAPI 生成で失敗する個体差があるため **未指定**
|
| 85 |
run_btn.click(
|
| 86 |
_run,
|
| 87 |
inputs=[pdf, unit, company, industry, use_llm, api_key],
|
| 88 |
outputs=[summary, kpis, ratios, scores],
|
|
|
|
| 89 |
)
|
| 90 |
|
| 91 |
return demo
|