Spaces:
Build error
Build error
Commit
ยท
e910ec9
1
Parent(s):
bbe6e89
add
Browse files
app.py
CHANGED
|
@@ -1,33 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# 1. ๊ฐ์ ๋ถ์
|
| 5 |
-
|
| 6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 8 |
-
sentiment_analyzer = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
| 9 |
|
| 10 |
-
# 2.
|
| 11 |
-
def
|
| 12 |
-
|
| 13 |
-
results
|
| 14 |
-
# ๊ฒฐ๊ณผ ๊ฐ๊ณต (label: 0=๋ถ์ , 1=๊ธ์ )
|
| 15 |
-
label = "๊ธ์ " if results[0]['label'] == "1" else "๋ถ์ "
|
| 16 |
-
score = results[0]['score']
|
| 17 |
-
return f"์์ธก: {label} (ํ๋ฅ : {score:.2f})"
|
| 18 |
|
| 19 |
-
# 3. Gradio
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
input_text = gr.Textbox(label="ํ๊ธ ํ
์คํธ ์
๋ ฅ", placeholder="ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์.")
|
| 26 |
-
output_text = gr.Textbox(label="๊ฒฐ๊ณผ")
|
| 27 |
-
|
| 28 |
-
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
| 29 |
-
analyze_button.click(analyze_sentiment_korean, inputs=input_text, outputs=output_text)
|
| 30 |
-
|
| 31 |
-
# 4. ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
| 32 |
if __name__ == "__main__":
|
| 33 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# 1. ์ฌ์ ํ์ต๋ ๊ฐ์ ๋ถ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
| 5 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# 2. ์์ธก ํจ์ ์ ์
|
| 8 |
+
def analyze_sentiment(text):
|
| 9 |
+
results = sentiment_pipeline(text)
|
| 10 |
+
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# 3. Gradio UI ๊ตฌ์ฑ
|
| 13 |
+
# - inputs: ํ
์คํธ ์
๋ ฅ
|
| 14 |
+
# - outputs: ๊ฒฐ๊ณผ(JSON ํ์ ํ์)
|
| 15 |
+
demo = gr.Interface(
|
| 16 |
+
fn=analyze_sentiment,
|
| 17 |
+
inputs=gr.Textbox(lines=3, placeholder="ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์"),
|
| 18 |
+
outputs="json",
|
| 19 |
+
title="๊ฐ์ ๋ถ์ ๋ฐ๋ชจ",
|
| 20 |
+
description="Hugging Face Transformers์ ํ์ดํ๋ผ์ธ์ ์ฌ์ฉํด ๊ฐ์ (๊ธ์ /๋ถ์ )์ ์์ธกํฉ๋๋ค."
|
| 21 |
+
)
|
| 22 |
|
| 23 |
+
# 4. ์คํ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
if __name__ == "__main__":
|
| 25 |
+
demo.launch()
|