Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,233 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import joblib
|
| 4 |
+
import torch
|
| 5 |
+
import numpy as np
|
| 6 |
+
import html
|
| 7 |
+
from transformers import AutoTokenizer, AutoModel, logging as hf_logging
|
| 8 |
|
| 9 |
+
# Hugging Face Transformers ๋ก๊น
๋ ๋ฒจ ์ค์
|
| 10 |
+
hf_logging.set_verbosity_error()
|
| 11 |
+
|
| 12 |
+
# โโโโโโโโโโ ์ค์ โโโโโโโโโโ
|
| 13 |
+
MODEL_NAME = "bert-base-uncased"
|
| 14 |
+
DEVICE = "cpu"
|
| 15 |
+
SAVE_DIR = "์ ์ฅ์ ์ฅ1" # ์ด ํด๋๊ฐ app.py์ ๊ฐ์ ์์น์ ์์ด์ผ ํฉ๋๋ค.
|
| 16 |
+
LAYER_ID = 4
|
| 17 |
+
SEED = 0
|
| 18 |
+
CLF_NAME = "linear"
|
| 19 |
+
|
| 20 |
+
# โโโโโโโโโโ ์ ์ญ ๋ชจ๋ธ ๋ก๋ (Gradio ์ฑ ์์ ์ ํ ๋ฒ ์คํ) โโโโโโโโโโ
|
| 21 |
+
# Streamlit์ @st.cache_resource ๋์ , ์ฑ ์์ ์ ๋ก๋๋๋๋ก ์ ์ญ ๋ณ์๋ก ๊ด๋ฆฌ
|
| 22 |
+
TOKENIZER_GLOBAL = None
|
| 23 |
+
MODEL_GLOBAL = None
|
| 24 |
+
W_GLOBAL, MU_GLOBAL, W_P_GLOBAL, B_P_GLOBAL = None, None, None, None
|
| 25 |
+
CLASS_NAMES_GLOBAL = None
|
| 26 |
+
MODELS_LOADED_SUCCESSFULLY = False
|
| 27 |
+
MODEL_LOADING_ERROR_MESSAGE = ""
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
print("Gradio App: ๋ชจ๋ธ ๋ก๋ฉ์ ์์ํฉ๋๋ค...")
|
| 31 |
+
lda_file_path = os.path.join(SAVE_DIR, f"lda_layer{LAYER_ID}_seed{SEED}.pkl")
|
| 32 |
+
clf_file_path = os.path.join(SAVE_DIR, f"{CLF_NAME}_layer{LAYER_ID}_projlda_seed{SEED}.pkl")
|
| 33 |
+
|
| 34 |
+
if not os.path.isdir(SAVE_DIR):
|
| 35 |
+
raise FileNotFoundError(f"์ค๋ฅ: ๋ชจ๋ธ ์ ์ฅ ๋๋ ํ ๋ฆฌ '{SAVE_DIR}'๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. '์ ์ฅ์ ์ฅ1' ํด๋๋ฅผ ํ์ธํ์ธ์.")
|
| 36 |
+
if not os.path.exists(lda_file_path):
|
| 37 |
+
raise FileNotFoundError(f"์ค๋ฅ: LDA ๋ชจ๋ธ ํ์ผ '{lda_file_path}'๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.")
|
| 38 |
+
if not os.path.exists(clf_file_path):
|
| 39 |
+
raise FileNotFoundError(f"์ค๋ฅ: ๋ถ๋ฅ๊ธฐ ๋ชจ๋ธ ํ์ผ '{clf_file_path}'๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.")
|
| 40 |
+
|
| 41 |
+
lda = joblib.load(lda_file_path)
|
| 42 |
+
clf = joblib.load(clf_file_path)
|
| 43 |
+
|
| 44 |
+
if hasattr(clf, "base_estimator"):
|
| 45 |
+
clf = clf.base_estimator
|
| 46 |
+
|
| 47 |
+
W_GLOBAL = torch.tensor(lda.scalings_, dtype=torch.float32, device=DEVICE)
|
| 48 |
+
MU_GLOBAL = torch.tensor(lda.xbar_, dtype=torch.float32, device=DEVICE)
|
| 49 |
+
W_P_GLOBAL = torch.tensor(clf.coef_, dtype=torch.float32, device=DEVICE)
|
| 50 |
+
B_P_GLOBAL = torch.tensor(clf.intercept_, dtype=torch.float32, device=DEVICE)
|
| 51 |
+
|
| 52 |
+
TOKENIZER_GLOBAL = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=True)
|
| 53 |
+
MODEL_GLOBAL = AutoModel.from_pretrained(
|
| 54 |
+
MODEL_NAME, output_hidden_states=True
|
| 55 |
+
).to(DEVICE).eval()
|
| 56 |
+
|
| 57 |
+
if hasattr(lda, 'classes_'):
|
| 58 |
+
CLASS_NAMES_GLOBAL = lda.classes_
|
| 59 |
+
elif hasattr(clf, 'classes_'):
|
| 60 |
+
CLASS_NAMES_GLOBAL = clf.classes_
|
| 61 |
+
|
| 62 |
+
MODELS_LOADED_SUCCESSFULLY = True
|
| 63 |
+
print("Gradio App: ๋ชจ๋ ๋ชจ๋ธ ๋ฐ ๋ฐ์ดํฐ ๋ก๋ ์ฑ๊ณต!")
|
| 64 |
+
|
| 65 |
+
except Exception as e:
|
| 66 |
+
MODEL_LOADING_ERROR_MESSAGE = f"๋ชจ๋ธ ๋ก๋ฉ ์ค ์ฌ๊ฐํ ์ค๋ฅ ๋ฐ์: {str(e)}\n'์ ์ฅ์ ์ฅ1' ํด๋์ ๋ด์ฉ๋ฌผ์ ํ์ธํด์ฃผ์ธ์."
|
| 67 |
+
print(MODEL_LOADING_ERROR_MESSAGE)
|
| 68 |
+
# ์ด ์ค๋ฅ๋ Gradio UI๋ฅผ ํตํด ์ฌ์ฉ์์๊ฒ ์ ๋ฌ๋ ์ ์๋๋ก ์ฒ๋ฆฌํ ์ ์์ต๋๋ค.
|
| 69 |
+
|
| 70 |
+
# โโโโโโโโโโ ํต์ฌ ๋ถ์ ํจ์ (Gradio ์ธํฐํ์ด์ค๊ฐ ํธ์ถ) โโโโโโโโโโ
|
| 71 |
+
def analyze_sentence_for_gradio(sentence_text, top_k_value):
|
| 72 |
+
if not MODELS_LOADED_SUCCESSFULLY:
|
| 73 |
+
# ๋ชจ๋ธ ๋ก๋ฉ ์คํจ ์ Gradio ์ถ๋ ฅ ํ์์ ๋ง์ถฐ ์ค๋ฅ ๋ฉ์์ง ๋ฐํ
|
| 74 |
+
error_html = f"<p style='color:red;'>์ด๊ธฐํ ์ค๋ฅ: {html.escape(MODEL_LOADING_ERROR_MESSAGE)}</p>"
|
| 75 |
+
# Gradio Interface๋ ์ ์๋ ๋ชจ๋ ์ถ๋ ฅ์ ๋ํด ๊ฐ์ ๋ฐ์์ผ ํฉ๋๋ค.
|
| 76 |
+
return error_html, "๋ชจ๋ธ ๋ก๋ฉ ์คํจ", "N/A", [] # HTML, ์์ธก๊ฒฐ๊ณผํ
์คํธ, ์์ธ๊ฒฐ๊ณผ(Label), TopK(DataFrame)
|
| 77 |
+
|
| 78 |
+
try:
|
| 79 |
+
# ์ ์ญ์์ ๋ก๋๋ ๋ชจ๋ธ ์ฌ์ฉ
|
| 80 |
+
tokenizer = TOKENIZER_GLOBAL
|
| 81 |
+
model = MODEL_GLOBAL
|
| 82 |
+
W, mu, w_p, b_p = W_GLOBAL, MU_GLOBAL, W_P_GLOBAL, B_P_GLOBAL
|
| 83 |
+
class_names = CLASS_NAMES_GLOBAL
|
| 84 |
+
|
| 85 |
+
# 1) ํ ํฐํ
|
| 86 |
+
enc = tokenizer(sentence_text, return_tensors="pt", truncation=True, max_length=510, padding=True)
|
| 87 |
+
input_ids = enc["input_ids"].to(DEVICE)
|
| 88 |
+
attn_mask = enc["attention_mask"].to(DEVICE)
|
| 89 |
+
|
| 90 |
+
if input_ids.shape[1] == 0:
|
| 91 |
+
return "<p style='color:orange;'>์
๋ ฅ ์ค๋ฅ: ์ ํจํ ํ ํฐ์ด ์์ต๋๋ค.</p>", "์
๋ ฅ ์ค๋ฅ", "N/A", []
|
| 92 |
+
|
| 93 |
+
# 2) ์๋ฒ ๋ฉ ๋ฐ ๊ทธ๋๋์ธํธ ์ค์
|
| 94 |
+
input_embeds = model.embeddings.word_embeddings(input_ids).clone().detach()
|
| 95 |
+
input_embeds.requires_grad_(True)
|
| 96 |
+
|
| 97 |
+
# 3) Forward pass
|
| 98 |
+
outputs = model(inputs_embeds=input_embeds, attention_mask=attn_mask, output_hidden_states=True)
|
| 99 |
+
cls_vec = outputs.hidden_states[LAYER_ID][:, 0, :]
|
| 100 |
+
|
| 101 |
+
# 4) LDA ํฌ์ ๋ฐ ๋ถ๋ฅ
|
| 102 |
+
z_projected = (cls_vec - mu) @ W
|
| 103 |
+
logit_output = z_projected @ w_p.T + b_p
|
| 104 |
+
probs = torch.softmax(logit_output, dim=1)
|
| 105 |
+
pred_idx = torch.argmax(probs, dim=1).item()
|
| 106 |
+
pred_prob_val = probs[0, pred_idx].item()
|
| 107 |
+
|
| 108 |
+
# 5) Gradient ๊ณ์ฐ
|
| 109 |
+
if input_embeds.grad is not None:
|
| 110 |
+
input_embeds.grad.zero_()
|
| 111 |
+
logit_output[0, pred_idx].backward()
|
| 112 |
+
if input_embeds.grad is None:
|
| 113 |
+
return "<p style='color:red;'>๋ถ์ ์ค๋ฅ: ๊ทธ๋๋์ธํธ ๊ณ์ฐ ์คํจ.</p>", "๋ถ์ ์ค๋ฅ", "N/A", []
|
| 114 |
+
grads = input_embeds.grad.clone().detach()
|
| 115 |
+
|
| 116 |
+
# 6) ์ค์๋ ์ ์ ๊ณ์ฐ
|
| 117 |
+
scores = (grads * input_embeds.detach()).norm(dim=2).squeeze(0)
|
| 118 |
+
scores_np = scores.cpu().numpy()
|
| 119 |
+
valid_scores = scores_np[np.isfinite(scores_np)]
|
| 120 |
+
if len(valid_scores) > 0 and valid_scores.max() > 0:
|
| 121 |
+
scores_np = scores_np / (valid_scores.max() + 1e-9)
|
| 122 |
+
else:
|
| 123 |
+
scores_np = np.zeros_like(scores_np)
|
| 124 |
+
|
| 125 |
+
# 7) HTML ์์ฑ
|
| 126 |
+
tokens = tokenizer.convert_ids_to_tokens(input_ids[0], skip_special_tokens=False)
|
| 127 |
+
html_tokens_list = []
|
| 128 |
+
cls_token_id, sep_token_id, pad_token_id = tokenizer.cls_token_id, tokenizer.sep_token_id, tokenizer.pad_token_id
|
| 129 |
+
|
| 130 |
+
for i, tok_str in enumerate(tokens):
|
| 131 |
+
if input_ids[0, i] == pad_token_id: continue
|
| 132 |
+
clean_tok_str = tok_str.replace("##", "") if "##" not in tok_str else tok_str[2:]
|
| 133 |
+
if input_ids[0, i] == cls_token_id or input_ids[0, i] == sep_token_id:
|
| 134 |
+
html_tokens_list.append(f"<span style='font-weight:bold;'>{html.escape(clean_tok_str)}</span>")
|
| 135 |
+
else:
|
| 136 |
+
score_val = scores_np[i] if i < len(scores_np) else 0
|
| 137 |
+
color = f"rgba(255, 0, 0, {max(0, min(1, score_val)):.2f})"
|
| 138 |
+
html_tokens_list.append(f"<span style='background-color:{color}; padding: 1px 2px; margin: 1px; border-radius: 3px; display:inline-block;'>{html.escape(clean_tok_str)}</span>")
|
| 139 |
+
|
| 140 |
+
html_output_str = " ".join(html_tokens_list).replace(" ##", "")
|
| 141 |
+
|
| 142 |
+
# Top-K ํ ํฐ (DataFrame์ฉ ๋ฆฌ์คํธ์ ๋ฆฌ์คํธ)
|
| 143 |
+
top_tokens_for_df = []
|
| 144 |
+
valid_indices = [idx for idx, token_id in enumerate(input_ids[0].tolist())
|
| 145 |
+
if token_id not in [cls_token_id, sep_token_id, pad_token_id] and idx < len(scores_np)]
|
| 146 |
+
sorted_valid_indices = sorted(valid_indices, key=lambda idx: -scores_np[idx])
|
| 147 |
+
for token_idx in sorted_valid_indices[:top_k_value]:
|
| 148 |
+
top_tokens_for_df.append([tokens[token_idx], f"{scores_np[token_idx]:.3f}"])
|
| 149 |
+
|
| 150 |
+
# ์์ธก ํด๋์ค ๋ ์ด๋ธ
|
| 151 |
+
predicted_class_label_str = str(pred_idx)
|
| 152 |
+
if class_names is not None and 0 <= pred_idx < len(class_names):
|
| 153 |
+
predicted_class_label_str = str(class_names[pred_idx])
|
| 154 |
+
|
| 155 |
+
prediction_summary_text = f"ํด๋์ค: {predicted_class_label_str}\nํ๋ฅ : {pred_prob_val:.3f}"
|
| 156 |
+
prediction_details_for_label = {"์์ธก ํด๋์ค": predicted_class_label_str, "ํ๋ฅ ": f"{pred_prob_val:.3f}"}
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
return html_output_str, prediction_summary_text, prediction_details_for_label, top_tokens_for_df
|
| 160 |
+
|
| 161 |
+
except Exception as e:
|
| 162 |
+
import traceback
|
| 163 |
+
tb_str = traceback.format_exc()
|
| 164 |
+
error_html = f"<p style='color:red;'>๋ถ์ ์ค ์ค๋ฅ ๋ฐ์: {html.escape(str(e))}</p><pre>{html.escape(tb_str)}</pre>"
|
| 165 |
+
print(f"Analyze_sentence_for_gradio error: {e}\n{tb_str}")
|
| 166 |
+
return error_html, "๋ถ์ ์คํจ", {"์ค๋ฅ": str(e)}, []
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
# โโโโโโโโโโ Gradio ์ธํฐํ์ด์ค ์ ์ โโโโโโโโโโ
|
| 170 |
+
# ์
๋ ฅ ์ปดํฌ๋ํธ
|
| 171 |
+
input_sentence = gr.Textbox(lines=3, label="๋ถ์ํ ์์ด ๋ฌธ์ฅ", placeholder="์ฌ๊ธฐ์ ์์ด ๋ฌธ์ฅ์ ์
๋ ฅํ์ธ์...")
|
| 172 |
+
input_top_k = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="ํ์ํ Top-K ์ค์ ํ ํฐ ์")
|
| 173 |
+
|
| 174 |
+
# ์ถ๋ ฅ ์ปดํฌ๋ํธ
|
| 175 |
+
output_html_visualization = gr.HTML(label="ํ ํฐ ์ค์๋ ์๊ฐํ")
|
| 176 |
+
output_prediction_summary = gr.Textbox(label="์์ธก ์์ฝ", lines=2) # ๊ฐ๋จํ ํ
์คํธ ์์ฝ์ฉ
|
| 177 |
+
output_prediction_details = gr.Label(label="์์ธก ์์ธ") # Label์ ๋์
๋๋ฆฌ๋ฅผ ์ ๋ณด์ฌ์ค
|
| 178 |
+
output_top_tokens_df = gr.DataFrame(headers=["Token", "Score"], label="Top-K ์ค์ ํ ํฐ", row_count=(1,"dynamic"), col_count=(2,"fixed"))
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
# Gradio Blocks๋ฅผ ์ฌ์ฉํ์ฌ ๋ ์ด์์ ๊ตฌ์ฑ (์ ํ ์ฌํญ, Interface๋ณด๋ค ์ ์ฐํจ)
|
| 182 |
+
with gr.Blocks(title="๋ฌธ์ฅ ํ ํฐ ์ค์๋ ๋ถ์๊ธฐ (Gradio)", theme=gr.themes.Soft()) as demo:
|
| 183 |
+
gr.Markdown("# ๐ ๋ฌธ์ฅ ํ ํฐ ์ค์๋ ๋ถ์๊ธฐ (Gradio)")
|
| 184 |
+
gr.Markdown("BERT์ LDA๋ฅผ ํ์ฉํ์ฌ ๋ฌธ์ฅ ๋ด ๊ฐ ํ ํฐ์ ์ค์๋๋ฅผ ์๊ฐํํฉ๋๋ค.")
|
| 185 |
+
|
| 186 |
+
with gr.Row():
|
| 187 |
+
with gr.Column(scale=2):
|
| 188 |
+
input_sentence.render()
|
| 189 |
+
input_top_k.render()
|
| 190 |
+
submit_button = gr.Button("๋ถ์ ์คํํ๊ธฐ ๐", variant="primary")
|
| 191 |
+
with gr.Column(scale=3):
|
| 192 |
+
output_prediction_summary.render()
|
| 193 |
+
output_prediction_details.render()
|
| 194 |
+
|
| 195 |
+
output_html_visualization.render()
|
| 196 |
+
output_top_tokens_df.render()
|
| 197 |
+
|
| 198 |
+
gr.Markdown("---")
|
| 199 |
+
gr.Markdown("<p style='text-align: center; color: grey;'>BERT ๊ธฐ๋ฐ ๋ฌธ์ฅ ๋ถ์ ๋ฐ๋ชจ (Gradio)</p>")
|
| 200 |
+
|
| 201 |
+
# ๋ฒํผ ํด๋ฆญ ์ ํจ์ ์ฐ๊ฒฐ
|
| 202 |
+
submit_button.click(
|
| 203 |
+
fn=analyze_sentence_for_gradio,
|
| 204 |
+
inputs=[input_sentence, input_top_k],
|
| 205 |
+
outputs=[output_html_visualization, output_prediction_summary, output_prediction_details, output_top_tokens_df]
|
| 206 |
+
)
|
| 207 |
+
|
| 208 |
+
# ์์ ์ถ๊ฐ
|
| 209 |
+
gr.Examples(
|
| 210 |
+
examples=[
|
| 211 |
+
["This is a great movie and I really enjoyed it!", 5],
|
| 212 |
+
["The weather is quite gloomy today.", 3],
|
| 213 |
+
["I am not sure if this is the right way to do it, but let's try.", 4]
|
| 214 |
+
],
|
| 215 |
+
inputs=[input_sentence, input_top_k],
|
| 216 |
+
outputs=[output_html_visualization, output_prediction_summary, output_prediction_details, output_top_tokens_df], # ์์ ์คํ ์์๋ ๋ชจ๋ ์ถ๋ ฅ ์ปดํฌ๋ํธ ํ์
|
| 217 |
+
fn=analyze_sentence_for_gradio, # ์์ ์คํ ์์๋ ๋์ผ ํจ์ ์ฌ์ฉ
|
| 218 |
+
cache_examples=False # ๋ชจ๋ธ์ด ์๋ ๊ฒฝ์ฐ True๋ก ํ๋ฉด ์์ ๋ก๋ฉ์ด ๋นจ๋ผ์ง ์ ์์ผ๋, ๋๋ฒ๊น
์ค์๋ False ๊ถ์ฅ
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
# Gradio ์ฑ ์คํ (Hugging Face Spaces์์๋ ์ด ๋ถ๋ถ์ด ์๋์ผ๋ก ์ฒ๋ฆฌ๋จ)
|
| 222 |
+
# ๋ก์ปฌ์์ ํ
์คํธ ์: demo.launch()
|
| 223 |
+
if __name__ == "__main__":
|
| 224 |
+
if not MODELS_LOADED_SUCCESSFULLY:
|
| 225 |
+
print("*"*80)
|
| 226 |
+
print("๊ฒฝ๊ณ : ๋ชจ๋ธ ๋ก๋ฉ์ ์คํจํ์ฌ Gradio ์ฑ์ด ์ ์์ ์ผ๋ก ์๋ํ์ง ์์ ์ ์์ต๋๋ค.")
|
| 227 |
+
print(f"์ค๋ฅ ๋ด์ฉ: {MODEL_LOADING_ERROR_MESSAGE}")
|
| 228 |
+
print("Gradio UI๋ ํ์๋์ง๋ง, '๋ถ์ ์คํํ๊ธฐ' ๋ฒํผ์ ๋๋ ์ ๋ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.")
|
| 229 |
+
print("`์ ์ฅ์ ์ฅ1` ํด๋ ๋ฐ ๋ด๋ถ ํ์ผ๋ค์ด `app.py`์ ๋์ผํ ๋๋ ํ ๋ฆฌ์ ์๋์ง ํ์ธํ์ธ์.")
|
| 230 |
+
print("*"*80)
|
| 231 |
+
# Hugging Face Spaces๋ app.py๋ฅผ ์คํํ๊ณ demo.launch()๋ฅผ ์ฐพ๊ฑฐ๋
|
| 232 |
+
# demo๋ผ๋ ์ด๋ฆ์ launchable Blocks/Interface ๊ฐ์ฒด๋ฅผ ์ฐพ์ต๋๋ค.
|
| 233 |
+
demo.launch()
|