KuuwangE commited on
Commit
e146c10
·
unverified ·
1 Parent(s): c201fa7

feat<update>: 결과물 반환 불가

Browse files
Files changed (4) hide show
  1. app.py +53 -41
  2. graded_results.csv +2 -2
  3. report.zip +1 -1
  4. src/grader.py +6 -1
app.py CHANGED
@@ -64,57 +64,69 @@ from huggingface_hub import upload_file
64
  from src.envs import RESULTS_REPO
65
  from src.grader import grade # grader.py 안에 채점 + 리포팅 함수
66
 
67
- def grade_csv(file):
68
- try:
69
- # 제출 CSV 로드
70
- submission_df = pd.read_csv(file.name)
71
-
72
- # 채점 및 리포트 생성
73
- score_df, report_dir = grade(submission_df, team_id="team")
74
 
75
- # 점수 CSV 저장
76
- output_file = "graded_results.csv"
77
- score_df.to_csv(output_file, index=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- # Hugging Face Hub 업로드 (선택적)
80
- upload_file(
81
- path_or_fileobj=output_file,
82
- path_in_repo=output_file,
83
- repo_id=RESULTS_REPO,
84
- repo_type="dataset",
85
- token=os.environ.get("HF_TOKEN"),
86
- )
87
 
88
- # 리포트 ZIP 압축
89
- report_zip = "report.zip"
90
- shutil.make_archive("report", 'zip', report_dir)
91
 
92
- return score_df, output_file, report_zip
93
 
94
- except Exception as e:
95
- return pd.DataFrame([{"Error": str(e)}]), None, None
96
 
97
 
98
  with gr.Blocks() as demo:
99
  gr.Markdown("## Hackathon CSV 채점기 + 리포트 생성기")
100
 
101
- with gr.Row():
102
- csv_input = gr.File(label="CSV 업로드", file_types=[".csv"])
103
-
104
- with gr.Row():
105
- df_output = gr.Dataframe(label="평가 지표 결과")
106
-
107
- with gr.Row():
108
- file_output = gr.File(label="점수 CSV 다운로드")
109
- report_output = gr.File(label="리포트 ZIP 다운로드")
110
-
111
- # 업로드 채점 실행
112
- csv_input.change(
113
- fn=grade_csv,
114
- inputs=csv_input,
115
- outputs=[df_output, file_output, report_output]
116
- )
 
 
 
 
 
 
 
 
 
 
 
117
 
118
  if __name__ == "__main__":
119
- demo.launch()
 
120
 
 
64
  from src.envs import RESULTS_REPO
65
  from src.grader import grade # grader.py 안에 채점 + 리포팅 함수
66
 
 
 
 
 
 
 
 
67
 
68
+ def grade_csv(file):
69
+ submission_df = pd.read_csv(file.name)
70
+
71
+ # 채점 및 리포트 생성
72
+ score_df, report_dir = grade(submission_df, team_id="team")
73
+
74
+ # 점수 CSV 저장
75
+ output_file = "graded_results.csv"
76
+ score_df.to_csv(output_file, index=False)
77
+
78
+ # Hugging Face Hub 업로드
79
+ upload_file(
80
+ path_or_fileobj=output_file,
81
+ path_in_repo=output_file,
82
+ repo_id=RESULTS_REPO,
83
+ repo_type="dataset",
84
+ token=os.environ.get("HF_TOKEN"),
85
+ )
86
 
87
+ # 리포트 ZIP 생성
88
+ report_zip = "report.zip"
89
+ shutil.make_archive("report", 'zip', report_dir)
 
 
 
 
 
90
 
91
+ # 그래프 이미지 파일 목록 (report_dir 안에 *.png)
92
+ image_files = [os.path.join(report_dir, f) for f in os.listdir(report_dir) if f.endswith(".png")]
 
93
 
94
+ return score_df, report_zip, image_files
95
 
 
 
96
 
97
 
98
  with gr.Blocks() as demo:
99
  gr.Markdown("## Hackathon CSV 채점기 + 리포트 생성기")
100
 
101
+ with gr.Tabs():
102
+ with gr.Tab("평가 요청"):
103
+ with gr.Row():
104
+ with gr.Row():
105
+ csv_input = gr.File(label="CSV 업로드", file_types=[".csv"])
106
+ password = gr.Textbox(label="Jupyter Notebook 비밀번호")
107
+ submit_button = gr.Button("평가 요청")
108
+ df_output = gr.Dataframe(label="평가 지표 결과")
109
+
110
+ with gr.Row():
111
+ report_output = gr.File(label="리포트 ZIP 다운로드")
112
+ image_gallery = gr.Gallery(
113
+ label="Plant별 비교 그래프",
114
+ show_label=True,
115
+ height="auto" # 높이는 자동
116
+ )
117
+
118
+ # 업로드 → 채점 실행
119
+ submit_button.click(
120
+ fn=grade_csv,
121
+ inputs=csv_input,
122
+ outputs=[df_output, report_output, image_gallery]
123
+ )
124
+
125
+ with gr.Tab("리더보드"):
126
+ with gr.Row():
127
+ gr.Textbox("ASDF")
128
 
129
  if __name__ == "__main__":
130
+ # demo.launch()
131
+ demo.launch(debug=True, show_error=True)
132
 
graded_results.csv CHANGED
@@ -1,2 +1,2 @@
1
- RMSE_AC,RMSE_AC_SCALED
2
- 493.28674800238497,0.35831099772441877
 
1
+ TEAM_ID,RMSE_AC,RMSE_AC_SCALED,NMAE_RANGE,NMAE_MEAN
2
+ 13,493.28674800238497,0.35831099772441877,0.0,0.0
report.zip CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f693bdb169bee6213e9c82af4ba8f46f33bf5498c1eb63931c72156c0b04cf10
3
  size 175825
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:108cf615dc3b4efc523a07f7568036674027ba1d31170af8c6455612e2e71d35
3
  size 175825
src/grader.py CHANGED
@@ -18,6 +18,8 @@ def grade(submission_df: pd.DataFrame, team_id: str = "submission"):
18
  'AC_POWER': 'ANS_AC_POWER',
19
  'DAILY_YIELD': 'ANS_DAILY_YIELD'
20
  })
 
 
21
 
22
  # merge
23
  merged_df = pd.merge(
@@ -26,6 +28,7 @@ def grade(submission_df: pd.DataFrame, team_id: str = "submission"):
26
  how='left'
27
  ).sort_values(by=['DATE_TIME', 'PLANT_ID', 'INVERTER_ID'])
28
 
 
29
  # scaler
30
  scaler = MinMaxScaler()
31
  merged_df['AC_POWER_SCALED'] = scaler.fit_transform(merged_df[['AC_POWER']])
@@ -37,7 +40,9 @@ def grade(submission_df: pd.DataFrame, team_id: str = "submission"):
37
 
38
  metrics = {
39
  "RMSE_AC": rmse_ac,
40
- "RMSE_AC_SCALED": rmse_ac_scaled
 
 
41
  }
42
 
43
  if 'DAILY_YIELD' in merged_df.columns:
 
18
  'AC_POWER': 'ANS_AC_POWER',
19
  'DAILY_YIELD': 'ANS_DAILY_YIELD'
20
  })
21
+ if 'SOURCE_KEY' in submission_df.columns:
22
+ submission_df = submission_df.rename(columns={"SOURCE_KEY": "INVERTER_ID"})
23
 
24
  # merge
25
  merged_df = pd.merge(
 
28
  how='left'
29
  ).sort_values(by=['DATE_TIME', 'PLANT_ID', 'INVERTER_ID'])
30
 
31
+
32
  # scaler
33
  scaler = MinMaxScaler()
34
  merged_df['AC_POWER_SCALED'] = scaler.fit_transform(merged_df[['AC_POWER']])
 
40
 
41
  metrics = {
42
  "RMSE_AC": rmse_ac,
43
+ "RMSE_AC_SCALED": rmse_ac_scaled,
44
+ "NMAE_RANGE": 0.0,
45
+ "NMAE_MEAN": 0.0,
46
  }
47
 
48
  if 'DAILY_YIELD' in merged_df.columns: