Spaces:
Runtime error
Runtime error
first check commit
Browse files- README.md +2 -2
- app.py +30 -0
- data/datalist.txt +2 -0
- libs/__init__.py +2 -0
- libs/__pycache__/__init__.cpython-37.pyc +0 -0
- libs/__pycache__/utils.cpython-37.pyc +0 -0
- libs/utils.py +89 -0
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
|
|
|
| 1 |
---
|
| 2 |
+
title: GradeSystem
|
| 3 |
+
emoji: π’
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, sys
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
from libs import *
|
| 7 |
+
|
| 8 |
+
import logging
|
| 9 |
+
|
| 10 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
with gr.Blocks(title="μμ
μ±μ νμΈ") as demo:
|
| 14 |
+
gr.Markdown("μμ
μ±μ νμΈμ μν΄, μμ
κ³Ό μ΄λ¦ νλ²μ μ
λ ₯νμΈμ.")
|
| 15 |
+
|
| 16 |
+
with gr.Row():
|
| 17 |
+
with gr.Column():
|
| 18 |
+
class_select = gr.Dropdown(choices=CLASS_LST, multiselect=False, label="μμ
μ ν")
|
| 19 |
+
name_input = gr.Textbox(label="μ΄λ¦ μ
λ ₯")
|
| 20 |
+
number_input = gr.Textbox(label="νλ² μ
λ ₯")
|
| 21 |
+
input_buttton = gr.Button("νμΈ")
|
| 22 |
+
|
| 23 |
+
with gr.Column():
|
| 24 |
+
image_output = gr.Image(label="μ±μ λΆν¬ κ·Έλ¦Ό")
|
| 25 |
+
data_output = gr.Dataframe(label="μ±μ ", interactive=True)
|
| 26 |
+
|
| 27 |
+
input_buttton.click(check_grade,inputs=[name_input, number_input, class_select], outputs = [image_output, data_output])
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
demo.launch(debug=True)
|
data/datalist.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
μ§λ₯νμμ€ν
(κ°).csv
|
| 2 |
+
μ§λ₯νμμ€ν
(λ).csv
|
libs/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from .utils import *
|
libs/__pycache__/__init__.cpython-37.pyc
ADDED
|
Binary file (165 Bytes). View file
|
|
|
libs/__pycache__/utils.cpython-37.pyc
ADDED
|
Binary file (3.01 kB). View file
|
|
|
libs/utils.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import matplotlib as mpl
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
from collections import Counter
|
| 8 |
+
from urllib.parse import quote
|
| 9 |
+
from huggingface_hub import hf_hub_download
|
| 10 |
+
from datasets import load_dataset
|
| 11 |
+
from datasets import Dataset
|
| 12 |
+
from huggingface_hub import HfApi, HfFolder
|
| 13 |
+
import logging
|
| 14 |
+
|
| 15 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
space_name = 'Grade_Dataset'
|
| 19 |
+
access_token = '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'
|
| 20 |
+
|
| 21 |
+
DATA_PATH = "https://huggingface.co/datasets/IgnoreLee/Grade_Dataset/tree/main"
|
| 22 |
+
IMG_PATH = os.path.join(DATA_PATH, "img")
|
| 23 |
+
CLASS_LST = ["μ§λ₯νμμ€ν
(κ°)", "μ§λ₯νμμ€ν
(λ)"]
|
| 24 |
+
|
| 25 |
+
def _get_csv_file(name,repo_id = "IgnoreLee/Grade_Dataset"):
|
| 26 |
+
return hf_hub_download(repo_id=repo_id,
|
| 27 |
+
filename=f"{name}.csv",
|
| 28 |
+
repo_type="dataset",
|
| 29 |
+
token="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")
|
| 30 |
+
|
| 31 |
+
def encoder(strings):
|
| 32 |
+
original = ["(", ")", "_", "-", ".", ",", "~", "/", ";", "\\", " "] + list(range(0, 9))
|
| 33 |
+
en_str = ""
|
| 34 |
+
for str in strings:
|
| 35 |
+
if str in original:
|
| 36 |
+
en_str += str
|
| 37 |
+
else:
|
| 38 |
+
en_str += quote(str)
|
| 39 |
+
return en_str
|
| 40 |
+
|
| 41 |
+
def draw_figure(count_dict:dict, mean, median) -> np.array:
|
| 42 |
+
# font_path = os.path.join(".","font","NanumGothic.ttf")
|
| 43 |
+
# font = mpl.font_manager.FontProperties(fname=font_path).get_name()
|
| 44 |
+
# mpl.rc('font', family=font)
|
| 45 |
+
|
| 46 |
+
fig = plt.figure()
|
| 47 |
+
plt.title("Overall score distribution")
|
| 48 |
+
plt.bar(count_dict.keys(), count_dict.values(), width=0.4, label = f"Total number of people {np.sum(list(count_dict.values()))}")
|
| 49 |
+
plt.axvline(mean.sum(), label=f"Mean : ({mean.sum():.2f})", color="r", linestyle=":")
|
| 50 |
+
plt.legend()
|
| 51 |
+
plt.xlabel = "Grade"
|
| 52 |
+
plt.ylabel = "Number of Person"
|
| 53 |
+
fig.canvas.draw()
|
| 54 |
+
return np.array(fig.canvas.renderer._renderer)
|
| 55 |
+
|
| 56 |
+
def csv_analysis(data:pd.DataFrame):
|
| 57 |
+
datas = data.values
|
| 58 |
+
mean, std, = datas.mean(0), datas.std(0)
|
| 59 |
+
ranking = np.sort(np.unique(datas.sum(1)))[::-1]
|
| 60 |
+
count_dict = Counter(datas.sum(1))
|
| 61 |
+
return (mean, std, ranking), count_dict
|
| 62 |
+
|
| 63 |
+
def check_grade(name, number, course:str):
|
| 64 |
+
assert course in CLASS_LST, gr.Error("μμ
μ΄λ¦μ νμΈν΄μ£ΌμΈμ.")
|
| 65 |
+
|
| 66 |
+
# Preprocessing
|
| 67 |
+
number = int(number)
|
| 68 |
+
# hf_folder = HfApi(space_name, f'{course}.csv')
|
| 69 |
+
# dataset = Dataset.from_config(hf_folder, data_files={"access_token": access_token})
|
| 70 |
+
dataset = load_dataset(f"IgnoreLee/Grade_Dataset", data_files = f"{course}.csv", use_auth_token=access_token)
|
| 71 |
+
logging.debug("Debug message: {}".format(dataset))
|
| 72 |
+
data = dataset['train'].to_pandas()
|
| 73 |
+
logging.debug("Debug message: {}".format(data))
|
| 74 |
+
data.set_index(list(data.columns[:2]), inplace=True)
|
| 75 |
+
logging.debug("Debug message: {}".format(data))
|
| 76 |
+
data.fillna(0, inplace=True)
|
| 77 |
+
cols = list(data.columns)
|
| 78 |
+
|
| 79 |
+
# Data Analysis
|
| 80 |
+
(mean, std, ranking), count_dict = csv_analysis(data)
|
| 81 |
+
logging.debug("Debug message: {}".format(count_dict))
|
| 82 |
+
finded_student = data.loc[number, name, :]
|
| 83 |
+
finded_student.loc[:,"ν©κ³"] = finded_student.loc[:,cols].values.sum(1)
|
| 84 |
+
median = np.median(finded_student[cols].values.sum(1))
|
| 85 |
+
|
| 86 |
+
# Draw Figure
|
| 87 |
+
img = draw_figure(count_dict, mean, median)
|
| 88 |
+
|
| 89 |
+
return img, finded_student
|