Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,50 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
3 |
|
4 |
+
model_name = "SJ-Donald/kcbert-large-unsmile"
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
7 |
|
8 |
+
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
9 |
+
|
10 |
+
# # ์ถ๋ก ํ์ดํ๋ผ์ธ ์ค์
|
11 |
+
# inference_pipeline = pipeline(
|
12 |
+
# "text-classification",
|
13 |
+
# model=model,
|
14 |
+
# tokenizer=tokenizer,
|
15 |
+
# return_all_scores=True,
|
16 |
+
# )
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
def classify_text(text):
|
22 |
+
"""
|
23 |
+
์ฃผ์ด์ง ํ
์คํธ๊ฐ ๋ถ์ ์ ํ์ง ์ฌ๋ถ๋ฅผ ํ๋ณํฉ๋๋ค.
|
24 |
+
|
25 |
+
Args:
|
26 |
+
- text (str): ํ๋ณํ ํ
์คํธ
|
27 |
+
|
28 |
+
Returns:
|
29 |
+
- result (str): '๋ถ์ ์ ํ ๋ด์ฉ์ด ํฌํจ๋์ด ์์ต๋๋ค.' or '์ ์ ํ ๋ด์ฉ์
๋๋ค.'
|
30 |
+
"""
|
31 |
+
results = classifier(text)
|
32 |
+
print(f"Debugging results: {results}") # ๊ฒฐ๊ณผ ํ์ธ์ฉ ์ถ๋ ฅ
|
33 |
+
|
34 |
+
for result in results:
|
35 |
+
# ๋ชจ๋ธ์ ๋ฐ๋ผ ๋ผ๋ฒจ์ด ๋ค๋ฅผ ์ ์์ต๋๋ค.
|
36 |
+
if result['label'] == '์
ํ/์์ค' and result['score'] > 0.5:
|
37 |
+
return "์์ค์
๋๋ค."
|
38 |
+
elif result['label'] == '์ฌ์ฑ/๊ฐ์กฑ' and result['score'] > 0.5:
|
39 |
+
return "์ฌ์ฑํ์ค์
๋๋ค"
|
40 |
+
|
41 |
+
|
42 |
+
return "์ ์ ํ ๋ด์ฉ์
๋๋ค."
|
43 |
+
|
44 |
+
# def greet(name):
|
45 |
+
# return "Hello ๊ณฝ์ ์ " + name + "!!"
|
46 |
+
|
47 |
+
# results = inference_pipeline(example_sentence)
|
48 |
+
|
49 |
+
demo = gr.Interface(fn=classify_text, inputs="textbox", title="๋ถ์ ์ ๋ฌธ์ฅ ๊ฒ์ถ๊ธฐ", theme="soft", description="๊ธฐ์ค: IMMORAL_NONE(๋ฌธ์ ์์), CRIME(๋ฒ์ฃ), SEXUAL(์ ์ ), HATE(ํ์ค), DISCRIMINATION(์ฐจ๋ณ), CENSURE(๋น๋), ABUSE(์์ค), VIOLENCE(ํญ๋ ฅ)", outputs="textbox")
|
50 |
demo.launch()
|