Spaces:
Sleeping

Corin1998 commited on
Commit
7d088ee
·
verified ·
1 Parent(s): cbc3ad5

Create App.tsx

Browse files
Files changed (1) hide show
  1. frontend/src/App.tsx +125 -0
frontend/src/App.tsx ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState } from 'react'
2
+ import UploadBox from './components/UploadBox'
3
+ import ScoreRadar from './components/ScoreRadar'
4
+ import StatCard from './components/StatCard'
5
+
6
+ type AnalyzeResponse = {
7
+ external_total: number
8
+ external_items: {category: string, name: string, raw: number, weight: number, score: number, reason: string}[]
9
+ ai: {
10
+ ai_score_total: number
11
+ ai_score_rationale: string
12
+ credit: { rating: string, rationale: string, recommended_limit_jpy: number, monitoring_frequency: string, payment_terms_days: number }
13
+ loan: { borrower_rating: string, loan_limit_jpy: number, term_months: number, interest_annual_pct: number, collateral_required: boolean, rationale: string }
14
+ investment: { est_market_cap_jpy?: number|null, suggested_investment_jpy?: number|null, attractiveness: string, rationale: string }
15
+ }
16
+ }
17
+
18
+ export default function App() {
19
+ const [data, setData] = useState<AnalyzeResponse|null>(null)
20
+ const [error, setError] = useState<string|null>(null)
21
+
22
+ const submit = async (file: File, company?: string, country?: string) => {
23
+ setError(null); setData(null)
24
+ const fd = new FormData()
25
+ fd.append('file', file)
26
+ if (company) fd.append('company', company)
27
+ if (country) fd.append('country', country)
28
+ const res = await fetch('/api/analyze', { method:'POST', body: fd })
29
+ if (!res.ok) {
30
+ const t = await res.text()
31
+ setError(`解析に失敗しました: ${res.status} ${t}`)
32
+ return
33
+ }
34
+ const j = await res.json() as AnalyzeResponse
35
+ setData(j)
36
+ }
37
+
38
+ return (
39
+ <div className="container">
40
+ <div style={{display:'flex', alignItems:'center', justifyContent:'space-between', marginBottom:16}}>
41
+ <h1 style={{fontWeight:800, fontSize:28}}>企業スコアリング(PDF→OpenAI)</h1>
42
+ <a className="badge" href="https://platform.openai.com/docs" target="_blank" rel="noreferrer">Powered by OpenAI</a>
43
+ </div>
44
+
45
+ <UploadBox onSubmit={submit} />
46
+
47
+ {error && <div className="card" style={{marginTop:16, color:'#991b1b', background:'#fee2e2'}}>{error}</div>}
48
+
49
+ {data && (
50
+ <div className="grid grid-3" style={{marginTop:16}}>
51
+ <StatCard title="外部スコア (0-100)" value={data.external_total.toFixed(1)} sub="提供アルゴリズムで算出" />
52
+ <StatCard title="AIスコア (0-100)" value={data.ai.ai_score_total.toFixed(1)} sub="モデルが総合判定" />
53
+ <StatCard title="推奨モニタリング" value={data.ai.credit.monitoring_frequency.toUpperCase()} sub={`${data.ai.credit.rating} / 限度額: ¥${(data.ai.credit.recommended_limit_jpy||0).toLocaleString()}`} />
54
+ </div>
55
+ )}
56
+
57
+ {data && (
58
+ <div className="grid grid-2" style={{marginTop:16}}>
59
+ <ScoreRadar items={data.external_items as any} />
60
+ <div className="card">
61
+ <div style={{fontWeight:700, marginBottom:8}}>AIスコアの根拠</div>
62
+ <p style={{whiteSpace:'pre-wrap'}}>{data.ai.ai_score_rationale}</p>
63
+
64
+ <div style={{marginTop:16}}>
65
+ <div style={{fontWeight:700, marginBottom:8}}>与信評価</div>
66
+ <ul className="small">
67
+ <li>格付: <b>{data.ai.credit.rating}</b></li>
68
+ <li>限度額: <b>¥{data.ai.credit.recommended_limit_jpy.toLocaleString()}</b></li>
69
+ <li>サイト: <b>{data.ai.credit.payment_terms_days}日</b></li>
70
+ <li>頻度: <b>{data.ai.credit.monitoring_frequency}</b></li>
71
+ <li className="small" style={{marginTop:6, whiteSpace:'pre-wrap'}}>{data.ai.credit.rationale}</li>
72
+ </ul>
73
+ </div>
74
+
75
+ <div style={{marginTop:16}}>
76
+ <div style={{fontWeight:700, marginBottom:8}}>融資評価</div>
77
+ <ul className="small">
78
+ <li>借入限度: <b>¥{data.ai.loan.loan_limit_jpy.toLocaleString()}</b></li>
79
+ <li>期間: <b>{data.ai.loan.term_months}ヶ月</b></li>
80
+ <li>金利(年): <b>{data.ai.loan.interest_annual_pct}%</b></li>
81
+ <li>担保: <b>{data.ai.loan.collateral_required ? '必要' : '不要'}</b></li>
82
+ <li className="small" style={{marginTop:6, whiteSpace:'pre-wrap'}}>{data.ai.loan.rationale}</li>
83
+ </ul>
84
+ </div>
85
+
86
+ <div style={{marginTop:16}}>
87
+ <div style={{fontWeight:700, marginBottom:8}}>投資評価</div>
88
+ <ul className="small">
89
+ <li>推定時価総額: <b>{data.ai.investment.est_market_cap_jpy ? `¥${data.ai.investment.est_market_cap_jpy.toLocaleString()}` : '—'}</b></li>
90
+ <li>推奨投資額: <b>{data.ai.investment.suggested_investment_jpy ? `¥${data.ai.investment.suggested_investment_jpy.toLocaleString()}` : '—'}</b></li>
91
+ <li>魅力度: <b>{data.ai.investment.attractiveness}</b></li>
92
+ <li className="small" style={{marginTop:6, whiteSpace:'pre-wrap'}}>{data.ai.investment.rationale}</li>
93
+ </ul>
94
+ </div>
95
+ </div>
96
+ </div>
97
+ )}
98
+
99
+ {data && (
100
+ <div className="card" style={{marginTop:16}}>
101
+ <div style={{fontWeight:700, marginBottom:8}}>詳細ブレイクダウン</div>
102
+ <table className="table">
103
+ <thead><tr><th>カテゴリ</th><th>指標</th><th>Raw(0-10)</th><th>重み(%)</th><th>寄与</th><th>理由</th></tr></thead>
104
+ <tbody>
105
+ {data.external_items.map((r,i)=>(
106
+ <tr key={i}>
107
+ <td>{r.category}</td>
108
+ <td>{r.name}</td>
109
+ <td className="mono">{r.raw.toFixed(2)}</td>
110
+ <td className="mono">{r.weight.toFixed(2)}</td>
111
+ <td className="mono">{r.score.toFixed(2)}</td>
112
+ <td className="small">{r.reason}</td>
113
+ </tr>
114
+ ))}
115
+ </tbody>
116
+ </table>
117
+ </div>
118
+ )}
119
+
120
+ <footer style={{marginTop:24}} className="small">
121
+ <p>⚠️ 本アプリは参考情報です。与信・投融資判断は必ず社内ポリシーと突合してください。</p>
122
+ </footer>
123
+ </div>
124
+ )
125
+ }