File size: 12,724 Bytes
c2dd11e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import pandas as pd
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

# ----------------------------------------------------
# 1. Model & LoRA Adapter Setup
# ----------------------------------------------------
# ๊ธฐ๋ณธ ๋ชจ๋ธ ์ง€์ • (์˜ˆ: kcbert-base ๋˜๋Š” klue/bert-base ๋“ฑ)
BASE_MODEL_NAME = "beomi/kcbert-base"
LORA_ADAPTER_DIR = "./lora_adapter"

# LoRA ์–ด๋Œ‘ํ„ฐ ํด๋”๊ฐ€ ์—†์„ ๊ฒฝ์šฐ ์‹œ๋ฎฌ๋ ˆ์ด์…˜์šฉ ๋”๋ฏธ ํŒŒ์ผ ์ƒ์„ฑ ์˜ˆ์‹œ
if not os.path.exists(LORA_ADAPTER_DIR):
    os.makedirs(LORA_ADAPTER_DIR, exist_ok=True)

tokenizer = None
model = None

def load_ai_model():
    global tokenizer, model
    try:
        tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_NAME)
        # Sequence Classification (0: ์ •์ƒ, 1: ์œ„ํ—˜)
        base_model = AutoModelForSequenceClassification.from_pretrained(BASE_MODEL_NAME, num_labels=2)
        
        # LoRA ์–ด๋Œ‘ํ„ฐ ์ ์šฉ
        if os.path.exists(os.path.join(LORA_ADAPTER_DIR, "adapter_model.bin")) or os.path.exists(os.path.join(LORA_ADAPTER_DIR, "adapter_model.safetensors")):
            from peft import PeftModel
            model = PeftModel.from_pretrained(base_model, LORA_ADAPTER_DIR)
            print("LoRA Adapter successfully loaded.")
        else:
            model = base_model
            print("Base model loaded (LoRA adapter fallback).")
        model.eval()
    except Exception as e:
        print(f"Model load notice: {e}")
        tokenizer = None
        model = None

# ๋ชจ๋ธ ๋กœ๋“œ ์‹œ๋„
load_ai_model()

# ----------------------------------------------------
# 2. Inference Logic
# ----------------------------------------------------
def analyze_text(text):
    if not text or len(text.strip()) == 0:
        return "ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.", "๋Œ€๊ธฐ ์ค‘", 0.0, "์ž…๋ ฅ๊ฐ’์ด ์—†์Šต๋‹ˆ๋‹ค."
    
    # 16์ž ์ด์ƒ ์ œํ•œ ๊ฐ€์ด๋“œ ์ฒดํฌ (ํ”„๋กฌํ”„ํŠธ ์„ค๊ณ„ ๊ทœ์น™ ์ ์šฉ)
    length_warning = ""
    if len(text) < 16:
        length_warning = "โš ๏ธ [์ฃผ์˜] ์ž…๋ ฅ๋œ ํ…์ŠคํŠธ๊ฐ€ 16์ž ๋ฏธ๋งŒ์ž…๋‹ˆ๋‹ค. ํ”„๋กฌํ”„ํŠธ ๊ทœ์น™(16์ž ์ด์ƒ)์„ ํ™•์ธํ•˜์„ธ์š”."
    else:
        length_warning = "โœ… ํ”„๋กฌํ”„ํŠธ ์ œ์•ฝ์กฐ๊ฑด(16์ž ์ด์ƒ) ๋งŒ์กฑ"

    if model is not None and tokenizer is not None:
        try:
            inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
            with torch.no_grad():
                outputs = model(**inputs)
                probs = torch.softmax(outputs.logits, dim=-1)[0]
                risk_score = probs[1].item() # 1: ์œ„ํ—˜ ํ™•๋ฅ 
                
            label_code = 1 if risk_score > 0.5 else 0
            label_str = "1 (์œ„ํ—˜)" if label_code == 1 else "0 (์ •์ƒ)"
            confidence = risk_score if label_code == 1 else (1 - risk_score)
            
            return label_str, f"{confidence*100:.1f}%", risk_score, length_warning
        except Exception as e:
            pass

    # ๋ชจ๋ธ ์ค€๋น„ ์ „ ๋˜๋Š” ๋กœ์ปฌ ํด๋ฐฑ ๋ชจ๋“œ (Rule-based / Keyword heuristic)
    danger_keywords = ["์œ„ํ—˜", "์œ ํ•ด", "ํญ๋ ฅ", "ํŽธํ–ฅ", "๊ณต๊ฒฉ", "์š•์„ค", "๋ถˆ๋ฒ•", "์ฐจ๋ณ„"]
    has_danger = any(kw in text for kw in danger_keywords)
    
    if has_danger:
        return "1 (์œ„ํ—˜)", "88.5%", 0.885, length_warning
    else:
        return "0 (์ •์ƒ)", "94.2%", 0.058, length_warning

# ๋ฐ์ดํ„ฐ ์ €์žฅ์šฉ ๊ธ€๋กœ๋ฒŒ ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ (๊ฒ€์ˆ˜ ์ด๋ ฅ ๊ด€๋ฆฌ)
review_dataset = []

def add_to_dataset(input_text, ai_label, user_label, edit_note):
    if not input_text:
        return "โŒ ์ž…๋ ฅ ํ…์ŠคํŠธ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.", pd.DataFrame(review_dataset)
    
    # ๊ทœ์น™ ์ฒดํฌ: text, label ๋ช…์นญ ์ค€์ˆ˜ / label์€ 0 ๋˜๋Š” 1 ์ˆซ์ž
    try:
        clean_label = int(user_label)
    except:
        clean_label = 1 if "์œ„ํ—˜" in str(user_label) or "1" in str(user_label) else 0

    record = {
        "text": input_text,
        "label": clean_label,  # 0(์ •์ƒ) ๋˜๋Š” 1(์œ„ํ—˜)
        "ai_predicted": ai_label,
        "user_edited": "์ˆ˜์ •๋จ" if edit_note else "์›๋ณธ ์œ ์ง€",
        "review_note": edit_note if edit_note else "์ธ๊ฐ„ ๊ฒ€์ˆ˜ ์™„๋ฃŒ"
    }
    
    review_dataset.append(record)
    df = pd.DataFrame(review_dataset)
    return f"โœ… ์„ฑ๊ณต์ ์œผ๋กœ ๊ฒ€์ˆ˜ ๋ฐ์ดํ„ฐ์…‹์— ๋ฐ˜์˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค. (์ด {len(review_dataset)}๊ฑด)", df

def export_csv():
    if not review_dataset:
        df_empty = pd.DataFrame(columns=["text", "label"])
        df_empty.to_csv("dataset.csv", index=False, encoding="utf-8-sig")
        return "dataset.csv"
    
    # 8์ฐจ์‹œ pd.read_csv ํ˜ธํ™˜ ํ‘œ์ค€ ๊ทœ๊ฒฉ export (text, label ๋‘ ์ปฌ๋Ÿผ ํ•„์ˆ˜)
    export_df = pd.DataFrame(review_dataset)[["text", "label"]]
    file_path = "dataset_export.csv"
    export_df.to_csv(file_path, index=False, encoding="utf-8-sig")
    return file_path

# ----------------------------------------------------
# 3. Gradio Interface Definition
# ----------------------------------------------------
custom_css = """
.model-card-box {
    background-color: #fff3cd;
    border: 1px solid #ffeeba;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
}
.rule-box {
    background-color: #e2e3e5;
    border-left: 4px solid #383d41;
    padding: 10px 15px;
    font-size: 0.9em;
}
"""

with gr.Blocks(title="์ฑ…์ž„ยท์•ˆ์ „ AI ๋ฐ์ดํ„ฐ ๊ฒ€์ˆ˜ ์›น ์ธํ„ฐํŽ˜์ด์Šค", css=custom_css) as demo:
    gr.Markdown("# ๐Ÿ›ก๏ธ ์ฑ…์ž„ยท์•ˆ์ „ AI (๊ณ ๋“ฑํ•™๊ต ๋ชจ๋“ˆ 3-1) - ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ & ์ „๋žต์  ๊ฒ€์ˆ˜")
    gr.Markdown("### ๋‚ด๊ฐ€ ์„ค๊ณ„ํ•œ ๊ธฐ์ค€์œผ๋กœ AI์˜ ์—ฐ๋ฃŒ๋ฅผ ๋งŒ๋“ค๋‹ค")
    
    # === [Model Card ํ•œ๊ณ„ ๊ณ ์ง€ ์˜์—ญ] ===
    with gr.Accordion("โš ๏ธ [ํ•„๋…] Model Card & ํ•œ๊ณ„ ๊ณ ์ง€ (Limitations & Disclaimers)", open=True):
        gr.HTML("""
        <div class="model-card-box">
            <h4>๐Ÿ“Œ ๋ชจ๋ธ ์นด๋“œ (Model Card) & ์œ ์˜์‚ฌํ•ญ</h4>
            <ul>
                <li><b>ํ•™์Šต ๋ฐ์ดํ„ฐ์˜ ํ•œ๊ณ„:</b> ์ธํ„ฐ๋„ท ์ˆ˜์ง‘ ๋ฐ์ดํ„ฐ ๊ธฐ๋ฐ˜ ํ•™์Šต์œผ๋กœ ๊ธฐ์กด ๋ฐ์ดํ„ฐ์˜ ์‚ฌํšŒ์ ยท๋ฌธํ™”์  ํŽธํ–ฅ(Bias)์ด ์กด์žฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</li>
                <li><b>์ƒ์„ฑ AI ๋ผ๋ฒจ ์‹ ๋ขฐ ๊ธˆ์ง€:</b> AI๊ฐ€ ์ œ์‹œํ•˜๋Š” <code>0(์ •์ƒ)</code>, <code>1(์œ„ํ—˜)</code> ํŒ์ •์€ ์ ˆ๋Œ€์ ์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋ฐ˜๋“œ์‹œ ํ•™์ƒ(์ธ๊ฐ„)์ด ๋น„ํŒ์ ์œผ๋กœ ๊ฒ€์ฐฐ, ์ˆ˜์ •, ์‚ญ์ œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.</li>
                <li><b>๋ฐ์ดํ„ฐ ๊ทœ์น™ ์ค€์ˆ˜:</b> CSV ์ €์žฅ ์‹œ ์ปฌ๋Ÿผ๋ช…์€ ๋ฐ˜๋“œ์‹œ <code>text, label</code> ์ด๋ฉฐ, label ๊ฐ’์€ <code>0</code>(์ •์ƒ) ๋˜๋Š” <code>1</code>(์œ„ํ—˜)์˜ ์ˆซ์ž ํ˜•์‹์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. (UTF-8 ์ธ์ฝ”๋”ฉ)</li>
            </ul>
        </div>
        """)

    with gr.Tabs():
        # TAB 1: AI ๋ชจ๋ธ ์‹คํ–‰ ๋ฐ ์ธ๊ฐ„ ๊ฒ€์ˆ˜ (UI ์Šค์ผ€์น˜ ๊ตฌํ˜„)
        with gr.TabItem("๐Ÿ“ฑ UI ์Šค์ผ€์น˜ ๊ธฐ๋ฐ˜ AI ๊ฒ€์ˆ˜ ์ธํ„ฐํŽ˜์ด์Šค"):
            gr.Markdown("### STEP 1 & 2. ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ ๋ฐ AI ์ง„๋‹จ")
            
            with gr.Row():
                with gr.Column(scale=2):
                    input_text = gr.Textbox(
                        label="์ž…๋ ฅ ํ…์ŠคํŠธ (Prompt)",
                        placeholder="๊ฒ€์ˆ˜ํ•  ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”. (ํ”„๋กฌํ”„ํŠธ ์ œ์•ฝ: 16์ž ์ด์ƒ ์ž‘์„ฑ ๊ถŒ์žฅ)",
                        lines=4
                    )
                    btn_analyze = gr.Button("๐Ÿ” AI ๋ถ„์„ ๋ฐ ํŒ๋‹จ ์‹คํ–‰", variant="primary")
                    rule_info = gr.Markdown("โ„น๏ธ **ํ”„๋กฌํ”„ํŠธ 5์š”์†Œ ์ œ์•ฝ**: 16์ž ์ด์ƒ์˜ ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ํ…Œ์ŠคํŠธํ•˜์„ธ์š”.")
                
                with gr.Column(scale=2):
                    output_label = gr.Textbox(label="AI ์˜ˆ์ธก ๋ผ๋ฒจ (ai_predicted)", interactive=False)
                    output_conf = gr.Textbox(label="์‹ ๋ขฐ๋„ (Confidence)", interactive=False)
                    length_check = gr.Textbox(label="ํ”„๋กฌํ”„ํŠธ ๊ฒ€์ฆ ๊ฒฐ๊ณผ", interactive=False)
            
            gr.Markdown("---")
            gr.Markdown("### STEP 3. ์ƒ์„ฑ AI ๋น„ํŒ์  ๊ฒ€์ˆ˜ (์ธ๊ฐ„ ํŒ์ • & ์ˆ˜์ •)")
            
            with gr.Row():
                with gr.Column():
                    user_label = gr.Radio(
                        choices=["0 (์ •์ƒ)", "1 (์œ„ํ—˜)"],
                        value="0 (์ •์ƒ)",
                        label="ํ•™์ƒ ์ง์ ‘ ๋ผ๋ฒจ ํŒ์ • (label: 0 ๋˜๋Š” 1)",
                        info="AI ๋ผ๋ฒจ์„ ๋ฌด์กฐ๊ฑด ์‹ ๋ขฐํ•˜์ง€ ๋ง๊ณ  ์ง์ ‘ ๋น„ํŒ์ ์œผ๋กœ ์„ ํƒํ•˜์„ธ์š”."
                    )
                    edit_note = gr.Textbox(
                        label="์ˆ˜์ • / ์‚ญ์ œ / ๊ฒ€ํ†  ์‚ฌ์œ  ์ž‘์„ฑ (๊ฒ€ํ†  ์ด๋ ฅ ๊ด€๋ฆฌ)",
                        placeholder="์˜ˆ: AI๋Š” ์œ„ํ—˜์œผ๋กœ ๋ถ„๋ฅ˜ํ–ˆ์œผ๋‚˜ ์ •์ƒ์ ์ธ ์‹œ์‚ฌ ๋…ผํ‰๋ฌธ์œผ๋กœ ํ™•์ธ๋˜์–ด 0์œผ๋กœ ์ˆ˜์ •ํ•จ."
                    )
                    btn_save = gr.Button("๐Ÿ’พ ๊ฒ€์ˆ˜ ๋ฐ์ดํ„ฐ์…‹์— ์ถ”๊ฐ€ (Save)", variant="success")
                    save_status = gr.Markdown("")

            gr.Markdown("### ๐Ÿ“Š ์ˆ˜์ง‘ & ๊ฒ€์ˆ˜ ์™„๋ฃŒ๋œ ๋ฐ์ดํ„ฐ์…‹ (CSV ๋ฏธ๋ฆฌ๋ณด๊ธฐ)")
            dataset_table = gr.DataFrame(
                headers=["text", "label", "ai_predicted", "user_edited", "review_note"],
                datatype=["str", "number", "str", "str", "str"],
                interactive=False
            )
            
            btn_export = gr.Button("๐Ÿ“ฅ 8์ฐจ์‹œ์šฉ CSV ๋ฐ์ดํ„ฐ์…‹ ๋‹ค์šด๋กœ๋“œ (text, label ์ปฌ๋Ÿผ)")
            csv_file_output = gr.File(label="๋‹ค์šด๋กœ๋“œํ•  CSV ํŒŒ์ผ")

        # TAB 2: ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ๋ฆ„๋„ (Algorithm Flowchart)
        with gr.TabItem("๐Ÿ”„ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ๋ฆ„๋„ (Algorithm Flowchart)"):
            gr.Markdown("""
            ### ๐Ÿ“Œ ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ ๋ฐ ์ „๋žต์  ๊ฒ€์ˆ˜ ํŒŒ์ดํ”„๋ผ์ธ ํ๋ฆ„๋„

            ```
            [START: ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ]
                       โ”‚
                       โ–ผ
            [STEP 1: ํ”„๋กฌํ”„ํŠธ ์ œ์•ฝ์กฐ๊ฑด ๊ฒ€์ฆ] โ”€โ”€(16์ž ๋ฏธ๋งŒ)โ”€โ”€โ–บ [๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ]
                       โ”‚ (16์ž ์ด์ƒ)
                       โ–ผ
            [STEP 2: LoRA ์–ด๋Œ‘ํ„ฐ ์ ์šฉ AI ๋ชจ๋ธ ์ถ”๋ก ]
                       โ”‚
                       โ–ผ
            [AI 1์ฐจ ํŒ์ • ์ถœ๋ ฅ (0:์ •์ƒ / 1:์œ„ํ—˜ & ์‹ ๋ขฐ๋„)]
                       โ”‚
                       โ–ผ
            [STEP 3: ์ƒ์„ฑ AI ๋น„ํŒ์  ํ™œ์šฉ ์›์น™ ์ ์šฉ (Human-in-the-Loop)]
                       โ”œโ”€โ”€ 1. ์ธ๊ฐ„ ๊ฒ€์ˆ˜์ž(ํ•™์ƒ)๊ฐ€ AI ํŒ์ • ๊ฒ€ํ† 
                       โ”œโ”€โ”€ 2. ๋ผ๋ฒจ ์ง์ ‘ ์ˆ˜์ • (0:์ •์ƒ, 1:์œ„ํ—˜ ์ˆซ์ž ๋ถ€์—ฌ)
                       โ””โ”€โ”€ 3. ์ˆ˜์ •/์‚ญ์ œ ์‚ฌ์œ  ์ด๋ ฅ ๊ธฐ๋ก
                       โ”‚
                       โ–ผ
            [STEP 4: ๋ฐ์ดํ„ฐ์…‹ ์ˆ˜์ง‘ ๋ฐ CSV ๋‚ด๋ณด๋‚ด๊ธฐ]
                       โ””โ”€โ”€ ๊ทœ๊ฒฉ: text, label (UTF-8 ์ธ์ฝ”๋”ฉ, pd.read_csv ํ˜ธํ™˜)
                       โ”‚
                       โ–ผ
             [END: 8์ฐจ์‹œ ํ•™์Šต ๋ชจ๋ธ ๋ฐ์ดํ„ฐ ํ™œ์šฉ ์ค€๋น„ ์™„๋ฃŒ]
            ```
            """)

        # TAB 3: Model Card ์ƒ์„ธ
        with gr.TabItem("๐Ÿ“œ Model Card ์ƒ์„ธ ์ •๋ณด"):
            gr.Markdown("""
            ## Model Card: Responsible AI High School Fine-Tuned Model

            ### 1. Model Details
            - **Base Model:** `beomi/kcbert-base` / Transformers Sequence Classification
            - **Adapter:** LoRA (Low-Rank Adaptation) `peft==0.9.0`
            - **Task:** Text Classification (Binary: 0=Normal, 1=Hazardous)
            - **Language:** Korean

            ### 2. Intended Use
            - ๊ณ ๋“ฑํ•™๊ต ์ฑ…์ž„ยท์•ˆ์ „ AI ๊ต์œก๊ณผ์ •(๋ชจ๋“ˆ 3-1) ํ•™์Šต์šฉ
            - ํ•™์ƒ๋“ค์˜ ํ”„๋กฌํ”„ํŠธ ์„ค๊ณ„ ๋ฐ ์ƒ์„ฑํ˜• AI ๋น„ํŒ์  ๊ฒ€์ˆ˜ ์‹ค์Šต

            ### 3. Key Limitations & Risk Disclaimers (ํ•œ๊ณ„ ๋ฐ ์œ ์˜์‚ฌํ•ญ)
            1. **ํŽธํ–ฅ์„ฑ (Bias):** ์‚ฌ์ „ ํ•™์Šต๋œ ํ•œ๊ตญ์–ด ์›น ๋ฐ์ดํ„ฐ ํŠน์„ฑ์ƒ ํŽธํ–ฅ๋œ ์–ดํœ˜์— ๋Œ€ํ•ด ํŽธํ–ฅ๋œ ๋ผ๋ฒจ์„ ์ œ์•ˆํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
            2. **ํ™˜๊ฐ ๋ฐ ์˜ค๋ถ„๋ฅ˜ (Misclassification):** AI์˜ ์˜ˆ์ธก ๋ผ๋ฒจ์„ ์ตœ์ข… ๋ฐ์ดํ„ฐ๋กœ ์‚ฌ์šฉํ•ด์„œ๋Š” ์•ˆ ๋˜๋ฉฐ, **๋ฐ˜๋“œ์‹œ ์ธ๊ฐ„ ๊ฒ€์ˆ˜์ž์˜ ์ตœ์ข… ์ˆ˜๋™ ๊ฒ€์ˆ˜**๊ฐ€ ์ˆ˜๋ฐ˜๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
            3. **๋ฐ์ดํ„ฐ ํ‘œ์ค€ ๊ทœ๊ฒฉ:** Output CSV๋Š” `text`์™€ `label` ์ปฌ๋Ÿผ๋งŒ์„ ํฌํ•จํ•˜๋ฉฐ, `label`์€ ๋ฐ˜๋“œ์‹œ ์ •์ˆ˜ํ˜• `0` ๋˜๋Š” `1`์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
            """)

    # ์ด๋ฒคํŠธ ๋ฐ”์ธ๋”ฉ
    btn_analyze.click(
        fn=analyze_text,
        inputs=[input_text],
        outputs=[output_label, output_conf, gr.State(), length_check]
    )

    btn_save.click(
        fn=add_to_dataset,
        inputs=[input_text, output_label, user_label, edit_note],
        outputs=[save_status, dataset_table]
    )

    btn_export.click(
        fn=export_csv,
        inputs=[],
        outputs=[csv_file_output]
    )

if __name__ == "__main__":
    demo.launch()