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 
ab0a4bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b1f4324
ab0a4bd
 
 
 
 
8c5b5a1
ab0a4bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b1f4324
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
import gradio as gr
import re
import hashlib
import mysql.connector as mydb
import time
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import japanize_matplotlib

from google import genai
from google.genai import types
import os
from dotenv import load_dotenv
import tempfile
import os
import msal
import json
import logging
import logging.handlers
import requests

matplotlib.use('Agg') # 重要な設定

load_dotenv(verbose=True)

try:
    with open("parameters.json") as f:
        config = json.load(f)
except FileNotFoundError:
    print("Error: parameters.json not found. Please create the file.")
    config = {}

# msal.ConfidentialClientApplicationのインスタンス化
if config:
    app = msal.ConfidentialClientApplication(
        config["client_id"], authority=config["authority"],
        client_credential=config["secret"],
    )

client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])

eval_kijyun = "評価会議のための質問事項(ディスカッションガイド)1. イントロダクションと全体像の確認対象質問・論点目的評価者「この評価レポートの意図は、過去を裁くことではなく、今後の成長を最大化することです。まず、レポートの全体的な評価について、あなたの最初の感想を教えてください。」建設的な雰囲気を作り、自己評価と他者評価のギャップを認識させる。評価者「期間を通じて、あなたが設定していた最も重要な目標は何でしたか?その目標達成について、自己評価はどの程度ですか?」評価の焦点を合わせ、本人の認識を明確にする。2. 業績評価に関する質問(成果の深掘り)対象質問・論点目的コンサルタント「期間中、あなたが最も価値を提供できたと実感しているプロジェクト(または成果物)はどれですか?具体的にクライアントにどのようなインパクトを与えましたか?」本人が誇る成果を確認し、具体的な事例を掘り下げる。評価者「『プロジェクト〇〇』での目標達成度は高いと評価しましたが、その成功の**最も大きな要因(KFS)**は何だったと考えますか?」成功の再現性を高めるための要因分析を促す。評価者「逆に、目標を達成できなかった、あるいは難航したプロジェクトについて、主要なボトルネックは何でしたか?それはコントロール可能な要因とコントロール不能な要因のどちらでしたか?」失敗からの学びを引き出し、客観的な状況分析力を評価する。評価者「ファームへの貢献(ナレッジ共有、採用など)で特に注力した点はありますか?その活動を通じてチームにどのような変化をもたらしましたか?」チーム・組織へのコミットメントと影響力を評価する。3. 能力評価に関する質問(スキルの具体化)対象質問・論点目的評価者「能力評価において『問題解決・論理的思考力』を高く評価しましたが、これを最もよく示していた具体的な行動や発言を一つ教えてください。」評価者の判断根拠を共有し、評価の納得度を高める。コンサルタント「次期に向けて、コンサルタントとして最も強化が必要だと感じているスキルは何ですか?なぜそれが重要だと考えますか?」課題意識と成長意欲、そして自己認識の正確さを評価する。評価者「あなたの提案資料は非常に論理的でしたが、**『伝達力』**の項目で改善点があると評価したのは、どのような場面(例:クライアントとの交渉、経営層へのプレゼン)でのことですか?」定性的な評価について、具体的な場面(コンテキスト)を示してフィードバックする。4. 行動評価に関する質問(プロセスとプロフェッショナリズム)対象質問・論点目的評価者「『プロジェクトA』の緊迫した状況下で、あなたはチームに対してどのようなリーダーシップを発揮しましたか?具体的な行動を教えてください。」プレッシャー下での行動やチームへの影響力を評価する。コンサルタント「期間中の業務プロセスを振り返って、より良い結果を出すために一つだけ変えられるとしたら、どの時点のどの行動を変えますか?」振り返りから改善につなげる内省力と、行動の重要性を理解しているかを評価する。評価者「クライアントとのコミュニケーションにおいて、特に信頼関係を深めるために意識的に行っていたことは何ですか?結果としてどうなりましたか?」クライアントリレーション構築における意識的な努力と、その結果を評価する。5. 総括とネクストステップ(キャリア開発)対象質問・論点目的評価者「総合的に見て、次の職位(例:マネージャー)へ昇進するために、現時点で最も不足していると判断するスキルや行動は何ですか? 具体的な基準に照らして説明します。」次の職位への期待値(卒業要件)を明確に伝え、ギャップを埋めるための目標設定につなげる。コンサルタント「この評価結果を踏まえ、次期の重点目標としてレポートに記載した内容(専門性向上やキャリアゴール)は、あなたのキャリアパスと合致していますか?」個人の目標とファームのニーズとの整合性を確認する。コンサルタント「目標達成のために、ファーム(評価者やチーム)にどのようなサポートやリソースを期待しますか?」育成計画に必要なリソースや環境整備について具体的に議論する。評価者「この評価レビューを通じて、他に懸念点や疑問点はありますか?私からのフィードバックに納得できない点があれば、ぜひ教えてください。」相互理解を深め、オープンな関係を維持したまま会議を終える。"

grounding_tool = types.Tool(
    google_search=types.GoogleSearch()
)

#configs = types.GenerateContentConfig(
#    tools=[grounding_tool]
#)

template = """
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>パフォーマンスレポート:名前</title>
    <link
        href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700&family=Roboto:wght@400;700&display=swap"
        rel="stylesheet">
    <style>
        /* --- 変数設定とリセット --- */
        :root {
            --primary-color: #0d1a2f;
            /* ディープネイビー/チャコールブルー */
            --secondary-color: #c9b16e;
            /* ゴールド/ブロンズ */
            --bg-light: #f5f5f5;
            --text-dark: #333;
            --shadow-gorgeous: 0 15px 30px rgba(0, 0, 0, 0.15);
        }
        body {
            font-family: 'Roboto', sans-serif;
            line-height: 1.6;
            background-color: var(--bg-light);
            color: var(--text-dark);
            padding: 30px;
        }
        /* --- コンテナとヘッダー --- */
        .review-container {
            max-width: 950px;
            margin: 0 auto;
            background-color: #fff;
            padding: 50px;
            border-radius: 10px;
            box-shadow: var(--shadow-gorgeous);
        }
        .review-header {
            text-align: center;
            border-bottom: 4px double var(--secondary-color);
            /* ゴージャスな二重線 */
            padding-bottom: 15px;
            margin-bottom: 40px;
        }
        .review-header h1 {
            font-family: 'Playfair Display', serif;
            /* ゴージャスなフォント */
            color: var(--primary-color);
            font-size: 3em;
            font-weight: 700;
            margin-bottom: 5px;
            letter-spacing: 1px;
        }
        .review-header p {
            color: #666;
            font-size: 1.1em;
        }
        /* --- セクションカード --- */
        .section-card {
            background-color: #ffffff;
            border: 1px solid #e0e0e0;
            padding: 30px;
            margin-bottom: 35px;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        }
        .section-card h2 {
            font-family: 'Playfair Display', serif;
            color: var(--primary-color);
            padding-bottom: 10px;
            margin-bottom: 25px;
            font-size: 1.8em;
            border-left: 8px solid var(--secondary-color);
            /* ゴールドの太いアクセントライン */
            padding-left: 18px;
            font-weight: 700;
        }
        /* --- 基本情報グリッド --- */
        .info-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px 40px;
        }
        .info-item label {
            font-weight: bold;
            color: var(--primary-color);
            display: inline-block;
            margin-right: 10px;
            font-size: 1em;
            text-transform: uppercase;
        }
        /* --- プロジェクトブロック --- */
        .project-block {
            margin-bottom: 40px;
            padding: 20px;
            border: 1px solid #eee;
            border-left: 5px solid var(--secondary-color);
            /* ゴールドの細いライン */
            border-radius: 8px;
            background-color: #fcfcfc;
        }
        .project-block h3 {
            color: var(--primary-color);
            font-size: 1.5em;
            border-bottom: 1px solid #ddd;
            padding-bottom: 5px;
            margin-bottom: 10px;
        }
        .project-subtitle {
            font-style: italic;
            color: #888;
            margin-bottom: 15px;
            font-size: 0.9em;
        }
        /* --- 評価詳細とコメントボックス --- */
        .evaluation-detail {
            margin-bottom: 25px;
        }
        .detail-title {
            color: var(--primary-color);
            font-size: 1.15em;
            margin-top: 15px;
            margin-bottom: 8px;
            font-weight: 700;
            text-transform: capitalize;
        }
        .comment-box {
            padding: 15px;
            border-radius: 4px;
            margin-top: 8px;
            line-height: 1.5;
        }
        .self-eval {
            background-color: #f7f9fd;
            /* 非常に薄い青 */
            border-left: 5px solid var(--primary-color);
        }
        .evaluator-comment {
            background-color: #fffdf5;
            /* 非常に薄いゴールド */
            border-left: 5px solid var(--secondary-color);
        }
        .comment-box p strong {
            color: var(--primary-color);
            margin-right: 5px;
        }
        /* --- 総合評価スコア --- */
        .overall-score-block {
            margin-top: 35px;
            padding: 25px;
            /*background-color: var(--primary-color);*/
            background-color: #fffdf5;
            /* 背景をディープネイビーに */
            border-radius: 10px;
            color: white;
            /* テキストを白に */
        }
        .overall-score-block h3 {
            color: var(--secondary-color);
            /* 見出しをゴールドに */
            margin-top: 0;
            border-bottom: 1px solid var(--secondary-color);
            padding-bottom: 10px;
            margin-bottom: 20px;
        }
        .score-grid {
            display: flex;
            justify-content: space-around;
            text-align: center;
        }
        .score-item label {
            display: block;
            font-weight: 400;
            color: #c0c0c0;
            margin-bottom: 5px;
        }
        /* --- 評価バッジ (ゴージャス版) --- */
        .rating-badge {
            font-weight: 700;
            padding: 4px 10px;
            border-radius: 4px;
            display: inline-block;
        }
        .score-badge {
            display: inline-block;
            width: 45px;
            height: 45px;
            line-height: 45px;
            text-align: center;
            border-radius: 50%;
            color: var(--primary-color);
            /* フォントをネイビーに */
            background-color: var(--secondary-color);
            /* 背景をゴールドに */
            font-weight: 700;
            font-size: 1.2em;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
            /* 影で立体感 */
        }
        .badge-a-plus {
            background-color: #4CAF50;
            /* A+はエメラルドグリーン */
            color: white;
        }
        .badge-a {
            background-color: var(--secondary-color);
            color: var(--primary-color);
        }
        /* --- 総括コメント --- */
        .total-summary {
            margin-top: 25px;
        }
        .large-comment {
            padding: 25px;
            border: 2px dashed var(--secondary-color);
            background-color: #fff;
        }
        .kudos {
            color: #4CAF50;
            /* 成功は緑 */
            font-weight: 700;
            display: block;
            margin-top: 5px;
            font-size: 1.15em;
        }
        .focus-area {
            color: var(--secondary-color);
            /* 成長領域はゴールド */
            font-weight: 700;
            display: block;
            margin-top: 15px;
            font-size: 1.15em;
        }
        /* --- 目標設定 --- */
        .goal-item {
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-left: 3px solid #eee;
            padding-left: 15px;
        }
        .goal-item p strong {
            color: var(--primary-color);
        }
        /* --- フッターと署名 --- */
        .review-footer {
            display: flex;
            justify-content: space-between;
            align-items: flex-end;
            margin-top: 50px;
            padding-top: 30px;
            border-top: 2px solid var(--primary-color);
            /* 濃い線 */
        }
        .signature {
            width: 30%;
        }
        .date {
            width: 30%;
            text-align: right;
        }
        .signature p,
        .date p {
            margin-bottom: 10px;
            font-style: italic;
            color: var(--primary-color);
            font-weight: bold;
        }
        .signature-line {
            display: block;
            width: 100%;
            border-bottom: 2px dotted var(--secondary-color);
            /* 署名欄はゴールドの点線 */
            margin-top: 8px;
            height: 1px;
        }
    </style>
</head>
<body>
    <div class="review-container">
        <header class="review-header">
            <h1>パフォーマンスレポート</h1>
            <p><strong>被評価者氏名:</strong> 被評価者氏名</p>
        </header>
        <section class="section-card basic-info">
            <h2>1. 基本情報</h2>
            <div class="info-grid">
                <div class="info-item">
                    <label>職位/役職:</label>
                    <span>シニアアソシエイト</span>
                </div>
                <div class="info-item">
                    <label>評価期間:</label>
                    <span>xxxx年4月1日 〜 xxxx年3月31日</span>
                </div>
                <div class="info-item">
                    <label>評価者氏名:</label>
                    <span>評価者名前</span>
                </div>
                <div class="info-item">
                    <label>評価日:</label>
                    <span>xxxx年xx月xx日</span>
                </div>
            </div>
        </section>
        <section class="section-card project-evaluation">
            <h2>2. プロジェクト別評価</h2>
            <div class="project-block">
                <h3>💼 XXXコスト削減プロジェクト</h3>
                <p class="project-subtitle">大手製造業のコスト構造改革</p>
                <div class="evaluation-detail">
                    <h4 class="detail-title">主要プロジェクトの達成目標</h4>
                    <div class="self-eval comment-box">
                        <p><strong>自己評価:</strong> 契約目標(コスト10%削減)に対し、12%の削減プランを策定し、初年度実行目標(5%削減)を達成。データ収集と経営層向け報告書作成を主導。
                        </p>
                    </div>
                    <div class="evaluator-comment comment-box rating-a-plus">
                        <p><strong>評価者コメント:</strong> <span
                                class="rating-badge badge-a-plus">A+評価</span>。田中さんのシミュレーションモデルは迅速かつ正確で、定量的目標を上回る結果に大きく貢献した。
                        </p>
                    </div>
                </div>
                <div class="evaluation-detail">
                    <h4 class="detail-title">クライアント満足度</h4>
                    <div class="self-eval comment-box">
                        <p><strong>自己評価:</strong>
                            クライアント担当者(部長層)と密に連携し、複雑なデータ要件を円滑に調整。プロジェクト後のアンケートで「非常に満足」を獲得し、後続案件の受注に貢献した。</p>
                    </div>
                    <div class="evaluator-comment comment-box">
                        <p><strong>評価者コメント:</strong>
                            クライアントとの専門的なやり取りはスムーズ。ただし、部門間の利害調整が難航した際、一歩踏み込んだファシリテーションの機会を逸した点は、マネージャー昇進に向けての改善点となる。</p>
                    </div>
                </div>
                <div class="evaluation-detail">
                    <h4 class="detail-title">実行力・責任感</h4>
                    <div class="self-eval comment-box">
                        <p><strong>自己評価:</strong> 期間を通じて、担当タスクの納期遅延やミスの発生はゼロ。クライアントへの提出物については、常にレビュー期限より1日早く準備を完了させた。
                        </p>
                    </div>
                    <div class="evaluator-comment comment-box">
                        <p><strong>評価者コメント:</strong>
                            計画的で極めて責任感が強い。自身のタスク管理については完璧。次期は、プロジェクト全体の進捗リスクを先読みし、評価者に報告する頻度を増やしてほしい。</p>
                    </div>
                </div>
            </div>
            <div class="project-block">
                <h3>🧪 XXX化学新規事業戦略策定プロジェクト</h3>
                <p class="project-subtitle">新規事業参入戦略</p>
                <div class="evaluation-detail">
                    <h4 class="detail-title">問題解決・論理的思考力</h4>
                    <div class="self-eval comment-box">
                        <p><strong>自己評価:</strong> 膨大な市場データから「参入すべきではない理由」を深く検証するクリティカルな仮説を提示し、戦略の精度を向上させた。</p>
                    </div>
                    <div class="evaluator-comment comment-box">
                        <p><strong>評価者コメント:</strong>
                            分析能力と論理構造の構築力は極めて高い。今後は、複雑な事象をさらにシンプルな「メッセージ」に落とし込む際の、大胆さと示唆の鋭さを磨く必要がある。</p>
                    </div>
                </div>
                <div class="evaluation-detail">
                    <h4 class="detail-title">専門知識とスキル</h4>
                    <div class="self-eval comment-box">
                        <p><strong>自己評価:</strong> 製造業のコストマネジメントに関する最新の手法を自習し、信越化学新規事業戦略策定プロジェクトで即座に適用した。財務モデリングスキルも向上した。
                        </p>
                    </div>
                    <div class="evaluator-comment comment-box">
                        <p><strong>評価者コメント:</strong> 技術的な専門性は申し分ない。特にデータ分析ツール(Python/R)の活用能力は、ファーム内でもトップクラス。</p>
                    </div>
                </div>
                <div class="evaluation-detail">
                    <h4 class="detail-title">リーダーシップ・影響力</h4>
                    <div class="self-eval comment-box">
                        <p><strong>自己評価:</strong> プロジェクトの終盤でチームの士気が低下した際、自発的にチームミーティングを企画し、残りのタスクを再分配することで、チームを再結集させた。
                        </p>
                    </div>
                    <div class="evaluator-comment comment-box">
                        <p><strong>評価者コメント:</strong>
                            個人的なタスク遂行能力の高さから、ときにチームメンバーのフォローを待たずに単独で進めてしまう傾向が見られた。今後は、仕事を「任せる(委譲する)」スキルを意識的に磨き、チーム全体の生産性を向上させてほしい。
                        </p>
                    </div>
                </div>
            </div>
        </section>
        <section class="section-card overall-evaluation">
            <h2>3. ファームへの貢献と総合評価</h2>
            <div class="evaluation-detail">
                <h4 class="detail-title">ファームへの貢献</h4>
                <div class="self-eval comment-box">
                    <p><strong>自己評価:</strong>
                        期間中に新たに参画したメンバー(2名)に対し、社内ナレッジベースの使い方、主要な分析ツールの操作方法についてOJTを実施。社内勉強会で「製造業のサプライチェーン改革」に関する発表を行った。
                    </p>
                </div>
                <div class="evaluator-comment comment-box">
                    <p><strong>評価者コメント:</strong> 新メンバーへの導入支援は模範的であり、早期戦力化に貢献。ナレッジ共有の取り組みも積極的で、ファームの知識資本への貢献度が高い。</p>
                </div>
            </div>
            <div class="evaluation-detail">
                <h4 class="detail-title">チームワーク・協調性</h4>
                <div class="self-eval comment-box">
                    <p><strong>自己評価:</strong> 新任のアソシエイトからの質問に常に快く答え、タスクが遅延しそうなメンバーに対しては、期日前に声をかけてサポートを提供した。</p>
                </div>
                <div class="evaluator-comment comment-box">
                    <p><strong>評価者コメント:</strong> チーム内での人望が厚く、ポジティブな職場環境づくりに貢献している。</p>
                </div>
            </div>
            <div class="overall-score-block">
                <h3>総合評価(評価者による)</h3>
                <div class="score-grid">
                    <div class="score-item">
                        <label>業績:</label>
                        <span class="score-badge badge-a">A</span>
                    </div>
                    <div class="score-item">
                        <label>能力:</label>
                        <span class="score-badge badge-a-plus">A+</span>
                    </div>
                    <div class="score-item">
                        <label>行動:</label>
                        <span class="score-badge badge-a">A</span>
                    </div>
                </div>
            </div>
            <div class="total-summary">
                <h3>総括(評価者記入欄)</h3>
                <div class="evaluator-comment comment-box large-comment">
                    <p><span class="kudos">期間中の最も優れていた点(Kudos):</span></p>
                    <p>田中さんは、期間を通じて極めて高い分析力と責任感を発揮し、特にコニカコスト削減プロジェクトでは目標を上回る成果に決定的に貢献しました。シミュレーションモデルの正確性と、期限厳守の姿勢は、ファームの信頼を高めています。次の職位(マネージャー)への昇進に必要な問題解決能力と専門知識は完全に満たしていると評価します。
                    </p>
                    <p><span class="focus-area">成長のための主要な改善点(Focus Area):</span></p>
                    <p>次期は、単なるタスク遂行者から「プロジェクトのオーナー」へと意識をシフトする必要があります。特に、クライアントやチームに対して、明確な方向性を提示するファシリテーション力と、自らのタスクを適切に任せて成果を出す「委譲と育成」のリーダーシップを重点的に強化してください。
                    </p>
                </div>
            </div>
        </section>
        <section class="section-card goals">
            <h2>4. 今後の目標とネクストステップ</h2>
            <div class="goal-item">
                <h4 class="detail-title">専門性向上</h4>
                <p><strong>目標設定:</strong> M&A後のPMI(Post Merger Integration)に関する専門知識とケーススタディを習得し、関連プロジェクトに参画する。</p>
                <p><strong>サポート・トレーニング計画:</strong> 外部M&A専門家によるトレーニングプログラム(全3回)への参加。プロジェクトB'のPMIフェーズへのアサインメント。</p>
            </div>
            <div class="goal-item">
                <h4 class="detail-title">キャリアゴール</h4>
                <p><strong>目標設定:</strong> 評価期間内にマネージャーへのプロモーションを目指す。そのために、チームメンバー2名に対し、デリバラブル作成に関するメンタリングを最低3ヶ月実施する。</p>
                <p><strong>サポート・トレーニング計画:</strong>
                    佐藤(評価者)による月次の1on1ミーティングを設定し、委譲と育成の進捗をレビューする。シニアマネージャーが主催するリーダーシップ・ワークショップへの招待。</p>
            </div>
        </section>
        <footer class="review-footer">
            <div class="signature">
                <p>被評価者 署名: <span class="signature-line"></span></p>
            </div>
            <div class="signature">
                <p>評価者 署名: <span class="signature-line"></span></p>
            </div>
            <div class="date">
                <p>日付: <span class="signature-line"></span></p>
            </div>
        </footer>
    </div>
</body>
</html>
"""


class DoSwitch:
    def __init__(self):
        # 状態(state)をインスタンス変数として保持
        self.is_logged = False
        self.first_exec = False
        self.lastlog = ""

    def log_on(self):
        self.is_logged = True

    def log_oout(self):
        self.log_on = False

    def first_executed(self):
        self.first_exec = True

my_switch = DoSwitch()

def change_input(prompt):
    if len(prompt) > 0:
        return gr.update(visible=True)
    else:
        return gr.update(visible=False)


def generate_review(prompt, scores, userid):
    #global chart_path
    chart_path = generate_chart(scores, userid)
    #print("chart_path",chart_path)
    print("chart_path",chart_path)
    current_chart_path = chart_path
    #current_chart_path = 'https://www.ryhintl.com/images/curchart.png'

    global template
    template = '''
<!DOCTYPE html>
<html lang="ja">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>パフォーマンスレポート:名前 (静的版)</title>
    <link
        href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700&family=Roboto:wght@400;700&display=swap"
        rel="stylesheet">
    <style>
        
        :root {
            --primary-color: #0d1a2f;
            /* ディープネイビー/チャコールブルー */
            --secondary-color: #c9b16e;
            /* ゴールド/ブロンズ */
            --bg-light: #f5f5f5;
            --text-dark: #333;
            --shadow-gorgeous: 0 15px 30px rgba(0, 0, 0, 0.15);
        }

        body {
            font-family: 'Roboto', sans-serif;
            line-height: 1.6;
            background-color: var(--bg-light);
            color: var(--text-dark);
            padding: 30px;
        }

        /* --- コンテナとヘッダー --- */
        .review-container {
            max-width: 950px;
            margin: 0 auto;
            background-color: #fff;
            padding: 50px;
            border-radius: 10px;
            box-shadow: var(--shadow-gorgeous);
        }

        .review-header {
            text-align: center;
            border-bottom: 4px double var(--secondary-color);
            /* ゴージャスな二重線 */
            padding-bottom: 15px;
            margin-bottom: 40px;
        }

        .review-header h1 {
            font-family: 'Playfair Display', serif;
            /* ゴージャスなフォント */
            color: var(--primary-color);
            font-size: 3em;
            font-weight: 700;
            margin-bottom: 5px;
            letter-spacing: 1px;
        }

        .review-header p {
            color: #666;
            font-size: 1.1em;
        }

        /* --- セクションカード --- */
        .section-card {
            background-color: #ffffff;
            border: 1px solid #e0e0e0;
            padding: 30px;
            margin-bottom: 35px;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        }

        .section-card h2 {
            font-family: 'Playfair Display', serif;
            color: var(--primary-color);
            padding-bottom: 10px;
            margin-bottom: 25px;
            font-size: 1.8em;
            border-left: 8px solid var(--secondary-color);
            /* ゴールドの太いアクセントライン */
            padding-left: 18px;
            font-weight: 700;
        }

        /* --- 基本情報グリッド --- */
        .info-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px 40px;
        }

        .info-item label {
            font-weight: bold;
            color: var(--primary-color);
            display: inline-block;
            margin-right: 10px;
            font-size: 1em;
            text-transform: uppercase;
        }

        /* --- プロジェクトブロック --- */
        .project-block {
            margin-bottom: 40px;
            padding: 20px;
            border: 1px solid #eee;
            border-left: 5px solid var(--secondary-color);
            /* ゴールドの細いライン */
            border-radius: 8px;
            background-color: #fcfcfc;
        }

        .project-block h3 {
            color: var(--primary-color);
            font-size: 1.5em;
            border-bottom: 1px solid #ddd;
            padding-bottom: 5px;
            margin-bottom: 10px;
        }

        .project-subtitle {
            font-style: italic;
            color: #888;
            margin-bottom: 15px;
            font-size: 0.9em;
        }

        /* --- 評価詳細とコメントボックス --- */
        .evaluation-detail {
            margin-bottom: 25px;
        }

        .detail-title {
            color: var(--primary-color);
            font-size: 1.15em;
            margin-top: 15px;
            margin-bottom: 8px;
            font-weight: 700;
            text-transform: capitalize;
        }

        .comment-box {
            padding: 15px;
            border-radius: 4px;
            margin-top: 8px;
            line-height: 1.5;
        }

        .self-eval {
            background-color: #f7f9fd;
            /* 非常に薄い青 */
            border-left: 5px solid var(--primary-color);
        }

        .evaluator-comment {
            background-color: #fffdf5;
            /* 非常に薄いゴールド */
            border-left: 5px solid var(--secondary-color);
        }

        .comment-box p strong {
            color: var(--primary-color);
            margin-right: 5px;
        }

        /* --- チャートコンテナ --- */
        /* 注: JavaScriptを削除したため、ここには静的な表とプレースホルダーを表示します */
        /*.chart-container {
            max-width: 90%;
            margin: 30px auto;
            padding: 20px;
            background-color: #ffffff;
            border: 1px solid #e0e0e0;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
        }*/

        .chart-container {
        /* Flexboxを有効化 */
        display: flex; 
        /* 子要素(画像)を水平方向の中央に配置 */
        justify-content: center; 
        /* 垂直方向も中央に配置したい場合は以下も追加 */
        /* align-items: center; */
    
    /* 適切な幅を設定(必要に応じて) */
    width: 100%; 
    /* 動作確認用に枠線をつけても良い */
    /* border: 1px solid red; */
}

        .chart-placeholder {
            min-height: 350px;
            background-color: #eee;
            border: 2px dashed var(--secondary-color);
            display: flex;
            align-items: center;
            justify-content: center;
            color: #999;
            font-size: 1.2em;
            margin-bottom: 20px;
            border-radius: 8px;
        }

        .score-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 15px;
        }

        .score-table th,
        .score-table td {
            border: 1px solid #ddd;
            padding: 12px;
            text-align: left;
        }

        .score-table th {
            background-color: var(--primary-color);
            color: white;
            font-weight: 700;
        }

        .score-table td:nth-child(2) {
            text-align: center;
            font-weight: 700;
            color: var(--secondary-color);
            font-size: 1.1em;
            background-color: #fffdf5;
        }

        /* --- 総合評価スコア --- */
        .overall-score-block {
            margin-top: 35px;
            padding: 25px;
            background-color: #fffdf5;
            /* 薄いゴールド背景を維持 */
            border-radius: 10px;
            border: 1px solid var(--secondary-color);
            /* ゴールドの枠線 */
            color: var(--primary-color);
            /* テキストカラーを濃い色に */
        }

        .overall-score-block h3 {
            color: var(--primary-color);
            /* 見出しをネイビーに */
            margin-top: 0;
            border-bottom: 1px solid var(--secondary-color);
            padding-bottom: 10px;
            margin-bottom: 20px;
        }

        .score-grid {
            display: flex;
            justify-content: space-around;
            text-align: center;
        }

        .score-item label {
            display: block;
            font-weight: 400;
            color: #666;
            /* テキスト色を調整 */
            margin-bottom: 5px;
        }

        /* --- 評価バッジ (ゴージャス版) --- */
        .rating-badge {
            font-weight: 700;
            padding: 4px 10px;
            border-radius: 4px;
            display: inline-block;
        }

        .score-badge {
            display: inline-block;
            width: 45px;
            height: 45px;
            line-height: 45px;
            text-align: center;
            border-radius: 50%;
            /*color: var(--primary-color);*/
            color: white;
            /* フォントをネイビーに */
            background-color: var(--secondary-color);
            /* 背景をゴールドに */
            font-weight: 700;
            font-size: 1.2em;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
            /* 影で立体感 */
        }

        .badge-a-plus {
            background-color: #4CAF50;
            /* A+はエメラルドグリーン */
            color: white;
        }

        .badge-a {
            background-color: var(--secondary-color);
            color: var(--primary-color);
        }

        /* --- 総括コメント --- */
        .total-summary {
            margin-top: 25px;
        }

        .large-comment {
            padding: 25px;
            border: 2px dashed var(--secondary-color);
            background-color: #fff;
        }

        .kudos {
            color: #4CAF50;
            /* 成功は緑 */
            font-weight: 700;
            display: block;
            margin-top: 5px;
            font-size: 1.15em;
        }

        .focus-area {
            color: var(--secondary-color);
            /* 成長領域はゴールド */
            font-weight: 700;
            display: block;
            margin-top: 15px;
            font-size: 1.15em;
        }

        /* --- 目標設定 --- */
        .goal-item {
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-left: 3px solid #eee;
            padding-left: 15px;
        }

        .goal-item p strong {
            color: var(--primary-color);
        }

        /* --- フッターと署名 --- */
        .review-footer {
            display: flex;
            justify-content: space-between;
            align-items: flex-end;
            margin-top: 50px;
            padding-top: 30px;
            border-top: 2px solid var(--primary-color);
            /* 濃い線 */
        }

        .signature {
            width: 30%;
        }

        .date {
            width: 30%;
            text-align: right;
        }

        .signature p,
        .date p {
            margin-bottom: 10px;
            font-style: italic;
            color: var(--primary-color);
            font-weight: bold;
        }

        .signature-line {
            display: block;
            width: 100%;
            border-bottom: 2px dotted var(--secondary-color);
            /* 署名欄はゴールドの点線 */
            margin-top: 8px;
            height: 1px;
        }
    </style>
</head>

<body>
    <div class="review-container">
        <header class="review-header">
            <h1>パフォーマンスレポート</h1>
            <p><strong>被評価者氏名:</strong> 被評価者氏名</p>
        </header>
        <section class="section-card basic-info">
            <h2>1. 基本情報</h2>
            <div class="info-grid">
                <div class="info-item">
                    <label>職位/役職:</label>
                    <span>シニアアソシエイト</span>
                </div>
                <div class="info-item">
                    <label>評価期間:</label>
                    <span>xxxx年4月1日 〜 xxxx年3月31日</span>
                </div>
                <div class="info-item">
                    <label>評価者氏名:</label>
                    <span>評価者名前</span>
                </div>
                <div class="info-item">
                    <label>評価日:</label>
                    <span>xxxx年xx月xx日</span>
                </div>
            </div>
        </section>
        <section class="section-card project-evaluation">
            <h2>2. プロジェクト別評価</h2>
            <div class="project-block">
                <h3>💼 XXXコスト削減プロジェクト</h3>
                <p class="project-subtitle">大手製造業のコスト構造改革</p>
                <div class="evaluation-detail">
                    <h4 class="detail-title">主要プロジェクトの達成目標</h4>
                    <div class="self-eval comment-box">
                        <p><strong>自己評価:</strong> 契約目標(コスト10%削減)に対し、12%の削減プランを策定し、初年度実行目標(5%削減)を達成。データ収集と経営層向け報告書作成を主導。
                        </p>
                    </div>
                    <div class="evaluator-comment comment-box rating-a-plus">
                        <p><strong>評価者コメント:</strong> <span
                                class="rating-badge badge-a-plus">A+評価</span>。田中さんのシミュレーションモデルは迅速かつ正確で、定量的目標を上回る結果に大きく貢献した。
                        </p>
                    </div>
                </div>
                <div class="evaluation-detail">
                    <h4 class="detail-title">クライアント満足度</h4>
                    <div class="self-eval comment-box">
                        <p><strong>自己評価:</strong>
                            クライアント担当者(部長層)と密に連携し、複雑なデータ要件を円滑に調整。プロジェクト後のアンケートで「非常に満足」を獲得し、後続案件の受注に貢献した。</p>
                    </div>
                    <div class="evaluator-comment comment-box">
                        <p><strong>評価者コメント:</strong>
                            クライアントとの専門的なやり取りはスムーズ。ただし、部門間の利害調整が難航した際、一歩踏み込んだファシリテーションの機会を逸した点は、マネージャー昇進に向けての改善点となる。</p>
                    </div>
                </div>
                <div class="evaluation-detail">
                    <h4 class="detail-title">実行力・責任感</h4>
                    <div class="self-eval comment-box">
                        <p><strong>自己評価:</strong> 期間を通じて、担当タスクの納期遅延やミスの発生はゼロ。クライアントへの提出物については、常にレビュー期限より1日早く準備を完了させた。
                        </p>
                    </div>
                    <div class="evaluator-comment comment-box">
                        <p><strong>評価者コメント:</strong>
                            計画的で極めて責任感が強い。自身のタスク管理については完璧。次期は、プロジェクト全体の進捗リスクを先読みし、評価者に報告する頻度を増やしてほしい。</p>
                    </div>
                </div>
            </div>
            <div class="project-block">
                <h3>🧪 XXX化学新規事業戦略策定プロジェクト</h3>
                <p class="project-subtitle">新規事業参入戦略</p>
                <div class="evaluation-detail">
                    <h4 class="detail-title">問題解決・論理的思考力</h4>
                    <div class="self-eval comment-box">
                        <p><strong>自己評価:</strong> 膨大な市場データから「参入すべきではない理由」を深く検証するクリティカルな仮説を提示し、戦略の精度を向上させた。</p>
                    </div>
                    <div class="evaluator-comment comment-box">
                        <p><strong>評価者コメント:</strong>
                            分析能力と論理構造の構築力は極めて高い。今後は、複雑な事象をさらにシンプルな「メッセージ」に落とし込む際の、大胆さと示唆の鋭さを磨く必要がある。</p>
                    </div>
                </div>
                <div class="evaluation-detail">
                    <h4 class="detail-title">専門知識とスキル</h4>
                    <div class="self-eval comment-box">
                        <p><strong>自己評価:</strong> 製造業のコストマネジメントに関する最新の手法を自習し、信越化学新規事業戦略策定プロジェクトで即座に適用した。財務モデリングスキルも向上した。
                        </p>
                    </div>
                    <div class="evaluator-comment comment-box">
                        <p><strong>評価者コメント:</strong> 技術的な専門性は申し分ない。特にデータ分析ツール(Python/R)の活用能力は、ファーム内でもトップクラス。</p>
                    </div>
                </div>
                <div class="evaluation-detail">
                    <h4 class="detail-title">リーダーシップ・影響力</h4>
                    <div class="self-eval comment-box">
                        <p><strong>自己評価:</strong> プロジェクトの終盤でチームの士気が低下した際、自発的にチームミーティングを企画し、残りのタスクを再分配することで、チームを再結集させた。
                        </p>
                    </div>
                    <div class="evaluator-comment comment-box">
                        <p><strong>評価者コメント:</strong>
                            個人的なタスク遂行能力の高さから、ときにチームメンバーのフォローを待たずに単独で進めてしまう傾向が見られた。今後は、仕事を「任せる(委譲する)」スキルを意識的に磨き、チーム全体の生産性を向上させてほしい。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <section class="section-card performance-summary">
            <h2>3. パフォーマンスKPIサマリー</h2>
            <p style="text-align: center; color: #666; margin-bottom: 20px;">評価者による6つの主要スキル項目の10段階評価</p>
            <div class="chart-container">
                <img src="'''+current_chart_path+'''" alt="レーダーチャート" width="500" height="500" />   
            </div>
        </section>

        <section class="section-card overall-evaluation">
            <h2>4. ファームへの貢献と総合評価</h2>
            <div class="evaluation-detail">
                <h4 class="detail-title">ファームへの貢献</h4>
                <div class="self-eval comment-box">
                    <p><strong>自己評価:</strong>
                        期間中に新たに参画したメンバー(2名)に対し、社内ナレッジベースの使い方、主要な分析ツールの操作方法についてOJTを実施。社内勉強会で「製造業のサプライチェーン改革」に関する発表を行った。
                    </p>
                </div>
                <div class="evaluator-comment comment-box">
                    <p><strong>評価者コメント:</strong> 新メンバーへの導入支援は模範的であり、早期戦力化に貢献。ナレッジ共有の取り組みも積極的で、ファームの知識資本への貢献度が高い。</p>
                </div>
            </div>
            <div class="evaluation-detail">
                <h4 class="detail-title">チームワーク・協調性</h4>
                <div class="self-eval comment-box">
                    <p><strong>自己評価:</strong> 新任のアソシエイトからの質問に常に快く答え、タスクが遅延しそうなメンバーに対しては、期日前に声をかけてサポートを提供した。</p>
                </div>
                <div class="evaluator-comment comment-box">
                    <p><strong>評価者コメント:</strong> チーム内での人望が厚く、ポジティブな職場環境づくりに貢献している。</p>
                </div>
            </div>
            <div class="overall-score-block">
                <h3>総合評価(評価者による)</h3>
                <div class="score-grid">
                    <div class="score-item">
                        <label>業績:</label>
                        <span class="score-badge badge-a">A</span>
                    </div>
                    <div class="score-item">
                        <label>能力:</label>
                        <span class="score-badge badge-a-plus">A+</span>
                    </div>
                    <div class="score-item">
                        <label>行動:</label>
                        <span class="score-badge badge-a">A</span>
                    </div>
                </div>
            </div>
            <div class="total-summary">
                <h3>総括(評価者記入欄)</h3>
                <div class="evaluator-comment comment-box large-comment">
                    <p><span class="kudos">期間中の最も優れていた点(Kudos):</span></p>
                    <p>田中さんは、期間を通じて極めて高い分析力と責任感を発揮し、特にコニカコスト削減プロジェクトでは目標を上回る成果に決定的に貢献しました。シミュレーションモデルの正確性と、期限厳守の姿勢は、ファームの信頼を高めています。次の職位(マネージャー)への昇進に必要な問題解決能力と専門知識は完全に満たしていると評価します。
                    </p>
                    <p><span class="focus-area">成長のための主要な改善点(Focus Area):</span></p>
                    <p>次期は、単なるタスク遂行者から「プロジェクトのオーナー」へと意識をシフトする必要があります。特に、クライアントやチームに対して、明確な方向性を提示するファシリテーション力と、自らのタスクを適切に任せて成果を出す「委譲と育成」のリーダーシップを重点的に強化してください。
                    </p>
                </div>
            </div>
        </section>
        <section class="section-card goals">
            <h2>5. 今後の目標とネクストステップ</h2>
            <div class="goal-item">
                <h4 class="detail-title">専門性向上</h4>
                <p><strong>目標設定:</strong> M&A後のPMI(Post Merger Integration)に関する専門知識とケーススタディを習得し、関連プロジェクトに参画する。</p>
                <p><strong>サポート・トレーニング計画:</strong> 外部M&A専門家によるトレーニングプログラム(全3回)への参加。プロジェクトB'のPMIフェーズへのアサインメント。</p>
            </div>
            <div class="goal-item">
                <h4 class="detail-title">キャリアゴール</h4>
                <p><strong>目標設定:</strong> 評価期間内にマネージャーへのプロモーションを目指す。そのために、チームメンバー2名に対し、デリバラブル作成に関するメンタリングを最低3ヶ月実施する。</p>
                <p><strong>サポート・トレーニング計画:</strong>
                    佐藤(評価者)による月次の1on1ミーティングを設定し、委譲と育成の進捗をレビューする。シニアマネージャーが主催するリーダーシップ・ワークショップへの招待。</p>
            </div>
        </section>
        <footer class="review-footer">
            <div class="signature">
                <p>被評価者 署名: <span class="signature-line"></span></p>
            </div>
            <div class="signature">
                <p>評価者 署名: <span class="signature-line"></span></p>
            </div>
            <div class="date">
                <p>日付: <span class="signature-line"></span></p>
            </div>
        </footer>
    </div>
</body>

</html>
'''

    try:
        final_prompt = prompt + f'{eval_kijyun}に基づいて{prompt}に記載されているコンサルタントのパフォーマンスをプロジェクト毎に分けて評価してください。必ず、評価者の総合評価を詳しく記載してください。答えは{template}に合わせてHTML形式にしてください'
        response = client.models.generate_content(
            model="gemini-2.5-flash",
            contents=final_prompt,
            #config=config,
        )
        #print(response.text)
        final_html = response.text
        #final_html = final_html.replace("```html", "")
        #final_html = final_html.replace("```", "")
        fin1 = final_html.find('```html')
        fin2 = final_html.rfind('```')
        final_html = final_html[fin1+7:fin2-3]
        #print("final_html:",final_html)

        with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".html", encoding="utf-8") as tmp_file:
            # レポート内容をファイルに書き込む
        #pdfkit.from_string(final_html, tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".pdf", encoding="utf-8").name)
            tmp_file.write(final_html)
            
            # ファイルパスを取得
            file_path = tmp_file.name
            weburl = put_file_to_graph_api(f"https://graph.microsoft.com/v1.0/sites/richardhuh.sharepoint.com,049de070-ff59-4a3e-b236-909dd06d18dc,928892cd-d109-40fe-9c67-c6fb82eb3b8d/drives/b!cOCdBFn_PkqyNpCd0G0Y3M2SiJIJ0f5AnGfG-4LrO428BidG9UKZQ4RHLePvALXz/root:/Work/{tmp_file.name}:/content", file_path)
            #print("weburl:", weburl)
            return final_html, '<div style="text-align: center; width: 100%;"><a href="' + weburl + '" style="display: block; width: fit-content; margin: 0 auto;">ファイルを表示</a></div>'
            #return final_html,file_path
    except Exception as e:
        return f"An error occurred: {e}", None


def update_prompt_suffix(prompt_suffix):
    if prompt_suffix == "投資判断用の要約":
        return temp_in
    else:
        return ""


def get_access_token() -> dict:
    """MSALを使用してアクセストークンを取得またはキャッシュから読み込む"""
    if not config:
        raise Exception("Configuration (parameters.json) is missing.")
    result = app.acquire_token_silent(config["scope"], account=None)

    if not result:
        logging.info("No suitable token exists in cache. Let's get a new one from AAD.")
        result = app.acquire_token_for_client(scopes=config["scope"])

    return result

def get_some_data_from_graph_api(endpoint: str) -> None:
    """Graph APIからデータを取得(今回は未使用だが残しておく)"""
    access_token = get_access_token()
    if "access_token" in access_token:
        graph_data = requests.get(
            endpoint,
            headers={'Authorization': 'Bearer ' + access_token['access_token']}, ).json()
        return graph_data
    else:
        raise Exception("===Failed to call MS Graph API. See stderr for details.===")
    
def put_file_to_graph_api(endpoint: str, file_path: str) -> dict:
    """Graph APIを使用してファイルをOneDrive/SharePointにアップロードする"""
    access_token = get_access_token()

    if "access_token" in access_token:
        try:
            with open(file_path, 'rb') as f:
                graph_data = requests.put(
                    endpoint,
                    headers={'Authorization': 'Bearer ' + access_token['access_token']},
                    data=f).json()
            print("graph_data:", graph_data.get('webUrl'))
            global fileurl
            # アップロードされたファイルのURLをグローバル変数に保存
            fileurl = graph_data.get('webUrl', 'URL not available')
            #print("fileurl:", fileurl)
            return fileurl
            #return graph_data
        except Exception as e:
            print(f"File upload error: {e}")
            raise Exception(f"===Failed to upload file to MS Graph API. Details: {e}===")
    else:
        raise Exception("===Failed to call MS Graph API. See stderr for details.===")



def open_signup_window():
    """
    gr.HTMLコンポーネントを使って、HTMLのリンクをボタンのように表示します。
    """
    # HTMLのaタグを生成し、target="_blank"で新しいタブを開くように指定します。
    # このリンクをCSSでボタンのようにスタイルします。
    # この文字列全体がHTMLとしてGradioにレンダリングされます。
    html_content = """
    <div style="text-align: center; padding: 20px;">
        <a href="https://accounts.google.com/v3/signin/identifier?authuser=0&continue=https://www.google.com/&ec=futura_exp_og_si_72776762_e&hl=ja&flowName=GlifWebSignIn&flowEntry=AddSession&dsh=S-1088503595%3A1757031827842666" target="_blank" 
           style="
               display: inline-block;
               padding: 15px 30px;
               background-color: #4CAF50;
               color: white;
               text-decoration: none;
               font-weight: bold;
               border-radius: 10px;
               box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
               transition: all 0.3s ease;
           " 
           onmouseover="this.style.backgroundColor='#45a049';"
           onmouseout="this.style.backgroundColor='#4CAF50';"
           onclick="this.style.display='none';"
        >
            サインアップページを開く
        </a>
    </div>
    """
    return gr.HTML(html_content)

def clean_text(text):
    # 改行とタブを削除
    return text.replace('\n', '').replace('\t', '').replace(' ', '')


def generate_chart(scores: str, userid: str):
    #global uid
    uid = userid
    print('chart-uid:',uid)
    #print("uid",uid)
    #scores = [int(score) for score in scores.split(",")]
    scores = eval(scores)
    labels = [
    '主要プロジェクトの達成目標',
    'クライアント満足度',
    '実行力・責任感',
    '問題解決・論理的思考力',
    '専門知識とスキル',
    'リーダーシップ・影響力'
    ]

    # データの準備:レーダーチャートは閉じたプロットが必要なため、最初のデータをリストの最後に追加
    num_vars = len(labels)
    data = np.concatenate((scores, [scores[0]]))
    angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False)
    angles = np.concatenate((angles, [angles[0]]))

    fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))

    # グラフのプロット
    ax.plot(angles, data, color='#c9b16e', linewidth=2, linestyle='solid', label='評価スコア')
    # 領域の塗りつぶし
    ax.fill(angles, data, color='#c9b16e', alpha=0.3)

    # 軸ラベルの設定
    ax.set_xticks(angles[:-1])
    ax.set_xticklabels(labels, size=12, y=0.01) # ラベルの位置調整

    # 目盛りの設定 (0から10まで)
    ax.set_yticks(np.arange(0, 11, 2))
    ax.set_ylim(0, 10) # 評価の最大値 (10点満点)
    ax.set_yticklabels([str(i) for i in np.arange(0, 11, 2)], color="grey", size=10)

    # タイトル
    ax.set_title('パフォーマンス KPI サマリー', size=16, color='#0d1a2f', y=1.1)

    # グリッド線のスタイル調整
    ax.grid(True, linestyle='--', alpha=0.7)

    # 凡例を表示
    ax.legend(loc='upper right', bbox_to_anchor=(0.1, 0.1))

    #plt.savefig(f'./{uid}.png', dpi=300)
    plt.savefig(f'./{uid}.png', dpi=300)

    #return '/Library/WebServer/Documents/charts/{uid}.png'
    return f'http://localhost/charts/{uid}.png'


def validate_username(username):
    if len(username) < 4:
        return "ユーザー名は4文字以上である必要があります"
    if not re.match("^[a-zA-Z0-9_]+$", username):
        return "ユーザー名には文字、数字、アンダースコアのみ使用できます"
    return None

def validate_email(email):
    if not re.match(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$", email):
        return "有効なメールアドレスを入力してください"
    return None

def validate_password(password):
    if len(password) < 8:
        return "パスワードは8文字以上でなければなりません"
    if not any(char.isdigit() for char in password):
        return "パスワードには少なくとも1つの数字を含める必要があります"
    if not any(char.isupper() for char in password):
        return "パスワードには少なくとも1つの大文字を含める必要があります"
    return None

def validate_phone(phone):
    if phone and not re.match(r"^\+?[0-9\s\-]+$", phone):
        return "有効な電話番号を入力してください"
    return None

def hash_password(password):
    return hashlib.sha256(password.encode()).hexdigest()


def login_user(username, password):
    conn = mydb.connect(
        host='www.ryhintl.com',
        port='36000',
        user='smairuser',
        password='smairuser',
        database='smair'
    )
    c = conn.cursor()
    hashed_pw = hash_password(password)
    sqlcmd = "SELECT * FROM gyoseki_users WHERE username = '"+username+"' AND password = '"+hashed_pw+"'"
    c.execute(sqlcmd)
    
    user = c.fetchone()
    conn.close()

    if user:
        return True, user
    return False, "ユーザー名またはパスワードが無効です"


def process_logout():
    time.sleep(1)
    return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)

# Login Logic
def process_login(username, password, current_user_info_state):
    username_error = validate_username(username)
    password_error = validate_password(password)

    if username_error:
        return gr.update(value=f"<p class='error-message'>{username_error}</p>"), False, None, None, gr.update(visible=True), gr.update(visible=False)
    elif password_error:
        return gr.update(value=f"<p class='error-message'>{password_error}</p>"), False, None, None, gr.update(visible=True), gr.update(visible=False)
    else:
        success, result = login_user(username, password)
        if success:
            user_info = {
                "id": result[0],
                "username": result[1],
                "email": result[2],
                "phone": result[4],
                "basic_format": result[5]
            }

            uid = result[5]
        
            conn = mydb.connect(
                host='www.ryhintl.com',
                port='36000',
                user='smairuser',
                password='smairuser',
                database='smair'
            )
            c = conn.cursor()
    
            sqlcmd = "SELECT contents FROM gyoseki_basic_format WHERE id = "+str(uid)
            c.execute(sqlcmd)
    
            content = c.fetchone()
            global basic_format
            basic_format = content
            conn.close()

            return gr.update(value="<p class='success-message'></p>"), True, username, user_info, gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), gr.update(visible=False)
            #return gr.update(value="<p class='success-message'></p>"), True, username, user_info, gr.update(visible=False), gr.update(visible=True)
        else:
            #return gr.update(visible=False), gr.update(visible=True)
            return gr.update(value=f"<p class='error-message'>{result}</p>"), False, None, None, gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
            #return gr.update(value=f"<p class='error-message'>{result}</p>"), False, None, None, gr.update(visible=True), gr.update(visible=False)


def get_grounded_response(prompt1, prompt2, prompt3):
    """
    Calls the Gemini API with the given prompt, applies grounding,
    and returns the response text with added citations.
    """
    try:
        final_prompt = f"{prompt1}{prompt2}{prompt3}を元に、プロジェクト毎に評価を含めて最終評価レポートを作成してください。"
        # Make the request to the Gemini model
        response = client.models.generate_content(
            model="gemini-2.5-flash",
            contents=final_prompt,
            #config=config,
        )

        return response.text
    except Exception as e:
        return f"An error occurred: {e}"

def set_eval_kijyun(kijun):
    global eval_kijyun
    eval_kijyun = kijun
    return "基準が設定されました"

def prompt_change(prompt):
    if len(prompt) > 0:
        return gr.update(visible=True)
    else:
        return gr.update(visible=False)

def show_tab_1():
    return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)

def show_tab_2():
    return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)

def show_tab_3():
    return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)


with gr.Blocks(title="パフォーマンス評価", theme=gr.themes.Soft(), css="""footer {visibility: hidden;} #header {display: flex; justify-content: space-between; align-items: center; font-size: 24px; font-weight: bold;} #logo {width: 50px; height: 50px;} 
    .gradio-container {
        background-color: #f8f9fa;
        /*width: 100%;
        height: 100%;
        background-image: url('https://images.unsplash.com/photo-1527181152855-fc03fc7949c8?auto=format&w=1000&dpr=2');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center center;*/
    }
    .main {
        background-color: #f8f9fa;
    }
    .logo-container {
        position: absolute;
        top: 1px;
        left: 20px;
        z-index: 1000;
    }
    .logo-container img {
        height: 30px;
        width: auto;
    }
    .title {
        font-size: 1.5rem;
        font-weight: 700;
        color: #2c3e50;
        text-align: center;
        margin-bottom: 1.5rem;
    }
    .subtitle {
        font-size: 0.1rem;
        color: #7f8c8d;
        text-align: center;
        margin-bottom: 2rem;
    }
               
    .rcard {
        background: #000055;
        border-radius: 15px;
        padding: 2rem;
        box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        margin-bottom: 1rem;
        height: 650px;
        overflow: hidden;
    }
               
    .card {
        background: white;
        border-radius: 15px;
        padding: 2rem;
        box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        margin-bottom: 1rem;
    }
    .success-message {
        color: #27ae60;
        text-align: center;
        margin-top: 1rem;
    }
    .error-message {
        color: #e74c3c;
        text-align: center;
        margin-top: 1rem;
    }
    .footer {
        text-align: center;
        margin-top: 1rem;
        color: #95a5a6;
        font-size: 0.8rem;
    }
    .avatar {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        margin: 0 auto 1rem auto;
        display: block;
        object-fit: cover;
        border: 3px solid #4a90e2;
    }
    
    .avatar:hover {
        transform: scale(1.2);
        border: 3px solid #4a90e2;
    }
    .gr-button {
        width: 100%;
        border-radius: 10px;
        padding: 10px;
        background-color: #4a90e2;
        color: white;
        border: none;
        font-weight: 500;
        transition: all 0.3s;
    }
    .gr-button:hover {
        background-color: #357abd;
        color: lightyellow;
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    }
    .gr-textinput, .gr-textbox {
        border-radius: 10px;
        padding: 10px;
        border: 1px solid #ced4da;
    }
    .my-custom-button {
        background-color: transparent !important; /* 緑色 */
        color: black !important;
        padding: 10px 20px !important;
        border: solid thin black !important;
        border-radius: 5px !important;
        cursor: pointer !important;
        font-size: 16px !important;
        width: 100%;
        transition: background-color 0.3s ease !important;
    }

    .my-custom-button:hover {
        background-color: #fff5ee !important; /* ホバー時の色 */
    }
""") as demo:
    gr.HTML('<div id="header"><span>🔖 パフォーマンス評価</span><img id="logo" src="https://www.ryhintl.com/images/ryhlogo/ryhlogo.png" width="64" height="64" alt="Logo"></div>')

    # State variables
    current_username = gr.State(None)
    current_user_info = gr.State(None)
    logged_in_state = gr.State(False)

    with gr.Sidebar(position="left", open=True):
        gr.Markdown("©️ Performance Review 2025")
        signin = gr.Button("サインイン", visible=True, elem_classes=["my-custom-button"], icon="https://img.icons8.com/fluency/48/azure-1.png")
        query = gr.Button("パフォーマンス評価", visible=False, elem_classes=["my-custom-button"], icon="https://img.icons8.com/fluency/48/orthogonal-view.png")
        smry = gr.Button("評価基準設定", visible=False, elem_classes=["my-custom-button"], icon="https://img.icons8.com/3d-fluency/48/domain.png")

    #with gr.Tabs() as tabs:
        # Set the first tab to be visible by default
    with gr.Column("タブ1", visible=False, elem_classes="card") as b1:
        signup_btn = gr.Button("サインアップ", elem_classes=["my-custom-button"], icon="https://img.icons8.com/color/48/000000/google-logo.png")
        login_username = gr.Textbox(label="ユーザー名", placeholder="ユーザー名を入力してください", value="fmuser1")
        login_password = gr.Textbox(label="パスワード", type="password", placeholder="パスワードを入力してください", value="fmuser1@Mails")
        login_status = gr.Markdown("")
        login_btn = gr.Button("サインイン")

        output_html = gr.HTML()

        signup_btn.click(
            fn=open_signup_window,
            inputs=[],
            outputs=[output_html]
        )

        login_btn.click(
            process_login,
            inputs=[login_username, login_password, current_user_info],
            outputs=[login_status, logged_in_state, current_username, current_user_info, signin, query, smry, b1]
        )
        
    with gr.Column("タブ2", visible=False) as b2:
        with gr.TabItem("パフォーマンス評価"):
            logout_btn = gr.Button("ログアウト")
            
            with gr.Row(visible=True) as filecomp:
                gr.Textbox(label="サンプル", show_copy_button=True, lines=10, value="""
パフォーマンスレポート

被評価者氏名	田中 太郎
職位/役職	シニアアソシエイト
評価期間: 2024年4月1日 〜 2025年3月31日
評価者名前 吉岡晴彦

1. 業績評価の概要(総合評価:A)
田中氏は、期間中、極めて優れた業績を達成しました。特に「コニカコスト削減プロジェクト」では、契約目標であるコスト10%削減に対し、12%の削減プランを策定し、初年度実行目標を達成しました。この成功において、田中氏が主導したシミュレーションモデルは、迅速かつ正確であり、定量的目標を上回る結果に決定的に貢献したと評価されています(A+評価)。

クライアント満足度も非常に高く、「非常に満足」の評価を得て後続案件の受注に貢献しましたが、部門間の利害調整が難航した際、一歩踏み込んだファシリテーションの機会を逸した点が、今後の改善点として挙げられています。また、ファームへの貢献としては、新メンバー2名へのOJT実施や、社内勉強会での積極的なナレッジ共有が高く評価されています。

2. 能力評価の概要(総合評価:A+)
田中氏の能力評価は「A+」であり、その核となる「問題解決・論理的思考力」は極めて高いと評価されています。

「信越化学新規事業戦略策定プロジェクト」では、市場データから**「参入すべきではない理由」を検証するクリティカルな仮説**を提示し、戦略の精度を向上させました。専門知識(特にデータ分析ツール:Python/Rの活用能力)についてもファーム内トップクラスとされています。

一方で、さらなる成長のためには、複雑な分析結果を経営層だけでなく非専門家(現場スタッフ)に対し、**シンプルな「メッセージ」や「必要性・メリット」として伝える際の「大胆さと示唆の鋭さ」**を磨くことが求められています。

3. 行動評価の概要(総合評価:A)
リーダーシップと責任感においても、田中氏は高い評価を得ています。「信越化学新規事業戦略策策定プロジェクト」の終盤でチームの士気が低下した際、自発的なミーティングを企画してタスクを再分配し、チームを再結集させたことは、その影響力を示す具体的な事例です。

また、担当タスクの納期遅延やミスの発生はゼロであり、極めて高い実行力と責任感を証明しています。

主要な改善点として、自身のタスク遂行能力の高さゆえに、チームメンバーへの「委譲(任せる)」スキルが不足している点が指摘されました。次期は、仕事を適切に分散させ、チーム全体の生産性を向上させるためのリーダーシップの強化が必要です。

4. 総括と次期への焦点
期間中の最も優れていた点(Kudos)
田中氏は、マネージャーへの昇進に必要な問題解決能力と専門知識を完全に満たしていると評価されています。高い分析力と責任感は、ファームの信頼構築に不可欠な要素です。

成長のための主要な改善点(Focus Area)
次期は、単なるタスク遂行者から**「プロジェクトのオーナー」へと意識をシフトすること**が最重要課題です。

具体的には、クライアントやチームに対して明確な方向性を提示するファシリテーション力と、自らのタスクを適切に任せて成果を出す「委譲と育成」のリーダーシップを重点的に強化する必要があります。""")
          
                user_input = gr.Textbox(
                    label="パフォーマンス:",
                    info="パフォーマンス評価を入力してください。",
                    lines=10
                )

                user_score = gr.Textbox(
                    label="評価者の総合評価:",
                    info="評価者の総合評価を入力してください。",
                    lines=1
                )

                user_userid = gr.Textbox(
                    label="評価者のID:",
                    info="評価者のIDを入力してください。",
                    lines=1
                )



        # Output component to display the model's response
        output_text = gr.HTML(
            label="パフォーマンス評価:",
            value='<div>結果</div>'
        )

        output_file = gr.HTML(
            label="パフォーマンス評価ファイル"
        )

        '''output_html = gr.File(
            label="パフォーマンス評価ファイル"
        )'''
        # Button to trigger the API call
        submit_button = gr.Button("生成", visible=False)

        user_input.change(fn=change_input, inputs=[user_input], outputs=[submit_button])

        # Connect the components: when the button is clicked,
        # the generate_response function is called with the user_input,
        # and the result is displayed in the output_text box.
        submit_button.click(
            fn=generate_review,
            inputs=[user_input, user_score, user_userid],
            outputs=[output_text, output_file]
            #outputs=[output_text, output_html]
        )

    with gr.Column("タブ3", visible=False) as b3:
        with gr.TabItem("パフォーマンス評価基準作成"):
            
            


            kijun_input = gr.Textbox(
                label="御社のパフォーマンス評価基準",
                lines=10,
                value="""
評価会議のための質問事項(評価ガイド)

1. イントロダクションと全体像の確認対象質問・論点目的評価者「この評価レポートの意図は、過去を裁くことではなく、今後の成長を最大化することです。まず、レポートの全体的な評価について、あなたの最初の感想を教えてください。」建設的な雰囲気を作り、自己評価と他者評価のギャップを認識させる。評価者「期間を通じて、あなたが設定していた最も重要な目標は何でしたか?その目標達成度はどの程度ですか?」評価の焦点を合わせ、本人の認識を明確にする。

2. 業績評価に関する質問(成果の深掘り)対象質問・論点目的コンサルタント「期間中、あなたが最も価値を提供できたと実感しているプロジェクト(または成果物)はどれですか?具体的にクライアントにどのようなインパクトを与えましたか?」本人が誇る成果を確認し、具体的な事例を掘り下げる。評価者「『プロジェクト〇〇』での目標達成度は高いと評価しましたが、その成功の**最も大きな要因(KFS)**は何だったと考えますか?」成功の再現性を高めるための要因分析を促す。評価者「逆に、目標を達成できなかった、あるいは難航したプロジェクトについて、主要なボトルネックは何でしたか?それはコントロール可能な要因とコントロール不能な要因のどちらでしたか?」失敗からの学びを引き出し、客観的な状況分析力を評価する。評価者「あなたの提案資料は非常に論理的でしたが、**『伝達力』**の項目で改善点があると評価したのは、どのような場面(例:クライアントとの交渉、経営層へのプレゼン)でのことですか?」定性的な評価について、具体的な場面(コンテキスト)を示してフィードバックする。

3. 行動評価に関する質問(プロセスとプロフェッショナリズム)対象質問・論点目的評価者「『プロジェクトA』の緊迫した状況下で、あなたはチームに対してどのようなリーダーシップを発揮しましたか?具体的な行動を教えてください。」プレッシャー下での行動やチームへの影響力を評価する。コンサルタント「期間中の業務プロセスを振り返って、より良い結果を出すために一つだけ変えられるとしたら、どの時点のどの行動を変えますか?」振り返りから改善につなげる内省力と、行動の重要性を理解しているかを評価する。評価者「クライアントとのコミュニケーションにおいて、特に信頼関係を深めるために意識的に行っていたことは何ですか?結果としてどうなりましたか?」クライアントリレーション構築における意識的な努力と、その結果を評価する。

4. 総括とネクストステップ(キャリア開発)対象質問・論点目的評価者「総合的に見て、次の職位(例:マネージャー)へ昇進するために、現時点で最も不足していると判断するスキルや行動は何ですか? 具体的な基準に照らして説明します。」次の職位への期待値(卒業要件)を明確に伝え、ギャップを埋めるための目標設定につなげる。コンサルタント「この評価レビューを通じて、他に懸念点や疑問点はありますか?私からのフィードバックに納得できない点があれば、ぜひ教えてください。」相互理解を深め、オープンな関係を維持したまま会議を終える。
                """
            )



            set_button = gr.Button("パフォーマンス評価基準", variant="primary",visible=True)
            
        set_button.click(
                fn=set_eval_kijyun,
                inputs=[kijun_input],
                outputs=[kijun_input]
            )

        
        user_input1 = gr.Textbox(
            label="評価プロファイル",
            info="""
            被評価者氏名	田中 太郎
            職位/役職	シニアアソシエイト
            評価期間 2024年4月1日 〜 2025年3月31日
            評価者名前	吉岡晴彦
            評価日	2025年12月2日
            """,
            lines=5,
            interactive=True # Allow user to type
        )

        user_input2 = gr.Textbox(
            label="評価1",
            info="""
            コニカコスト削減プロジェクト」の成果と次期マネージャーへの課題
            田中さんは、本プロジェクトにおいて、シニアアソシエイトとして期待される水準を大きく上回る成果を達成しました。特に、コスト削減の契約目標(10%)を上回る12%の削減プランの策定に決定的に貢献した、迅速かつ正確なシミュレーションモデル構築能力は特筆すべき点です。これは、田中さんが持つ高度な分析専門知識と、プロジェクト遂行における極めて高い実行力・責任感の証左であり、「担当タスクの納期遅延やミスの発生がゼロ」という事実からも裏付けられています。業績評価における「A+」は、この定量的な成果と、クライアントからの「非常に満足」という高い評価に基づいてい  ます。
            一方で、次期マネージャーへのプロモーションを視野に入れる上で、プロジェクトのオーナーシップの面で改善すべき点が浮き彫りになりました。クライアント満足度が高く、個別ステークホルダーへの配慮は優れているものの、「部門間の利害調整が難航した際、一歩踏み込んだファシリテーションの機会を逸した」という自己評価は、まさにこの課題を指し示しています。シニアアソシエイトは「タスクの最高責任者」ですが、マネージャーは「プロジェクト全体の結論と方向性の最高責任者」です。今後は、困難な状況で明確な「Go/No-Go」を提示し、コンセンサスを形成する「大胆なファシリテーション力」を重点的に磨く必要があります。これは、単なる調整役ではなく、プロジェクトを成功に導く推進力に直結します。""",
            lines=5,
            interactive=True # Allow user to type
        )

        user_input3 = gr.Textbox(
            label="評価2",
            info="""
            信越化学新規事業戦略策定プロジェクト」における知見の深化とリーダーシップの強化
            田中さんは、信越化学新規事業戦略策定プロジェクト」では、問題解決能力と論理的思考力がファーム内でトップクラスであることを改めて証明しました。特に、「一般的な推奨とは異なる**『参入すべきではない理由』を検証するクリティカルな仮説**」を提示したことは、膨大なデータに溺れることなく、真の戦略的な示唆を抽出する田中さんの本質を見抜く力を示しています。技術的な専門知識、特にPython/Rを用いたデータ分析能力は、チームの生産性を大きく押し上げました。
            しかし、この高度な専門性を、より広いビジネスインパクトに結びつけるための**「伝達力」と「委譲能力」の強化が求められます。複雑な分析結果を、経営層や非専門家である現場スタッフに対し、「なぜ、今これをやるべきか」というシンプルな「メッセージ」と「示唆の鋭さ」をもって伝えきる能力は、田中さんが今後、大規模プロジェクトを牽引するために不可欠なスキルです。高度な分析結果を「翻訳」し、組織全体を動かす「影響力」**を意識してほしい。
            また、リーダーシップの面では、士気の低下したチームを自発的に再結集させた功績は素晴らしいものの、「自身のタスク遂行能力の高さゆえに、チームメンバーへの**『委譲(任せる)スキルが不足している』」という指摘は重要です。マネージャーは、自分一人で成果を出すのではなく、チーム全体のパフォーマンスを最大化することが役割です。次期は、タスクを任せることでメンバーを成長させ、プロジェクトの生産性を複利的に高める「育成と委譲のリーダーシップ」**を意識的に実践していくことが、最重要課題となります。""",
            lines=5,
            interactive=True # Allow user to type
        )

        output_text = gr.Textbox(
            label="プレ・レビュー・レポート",
            lines=10,
            show_copy_button=True,
            interactive=False # Allow user to type
        )

         
        pre_button = gr.Button("プレ・レビュー・レポートを作成")

        pre_button.click(
            fn=get_grounded_response,
            inputs=[user_input1, user_input2, user_input3],
            outputs=output_text
        )
    
        signin.click(show_tab_1, inputs=None, outputs=[b1, b2, b3])
        query.click(show_tab_2, inputs=None, outputs=[b1, b2, b3])
        smry.click(show_tab_3, inputs=None, outputs=[b1, b2, b3])
        logout_btn.click(
            process_logout,
            inputs=[],
        outputs=[signin,query,smry,b2]
    )
    
demo.launch(favicon_path="favicon.ico")