nchime commited on
Commit
ce9cab0
โ€ข
1 Parent(s): 19a2bb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -3
app.py CHANGED
@@ -1,7 +1,50 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()