Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# ๊ฐ์ ๋ถ์ ๋ชจ๋ธ ๋ก๋
|
| 5 |
+
emotion_analyzer = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 6 |
+
|
| 7 |
+
# ์์ธก ํจ์
|
| 8 |
+
def analyze_emotion(text):
|
| 9 |
+
result = emotion_analyzer(text)[0]
|
| 10 |
+
label = result['label']
|
| 11 |
+
score = result['score'] * 100
|
| 12 |
+
return f"{label}, {score:.2f}%"
|
| 13 |
+
|
| 14 |
+
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
| 15 |
+
interface = gr.Interface(
|
| 16 |
+
fn=analyze_emotion, # ๋ถ์ ํจ์
|
| 17 |
+
inputs=gr.Textbox(lines=2, placeholder="ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์..."), # ์
๋ ฅ
|
| 18 |
+
outputs="text", # ์ถ๋ ฅ
|
| 19 |
+
title="๊ฐ์ ๋ถ์ ์ฑ",
|
| 20 |
+
description="์ฌ์ฉ์๊ฐ ์
๋ ฅํ ํ
์คํธ์ ๊ฐ์ ์ ๋ถ์ํ์ฌ ๋ ์ด๋ธ๊ณผ ํ๋ฅ ๊ฐ์ ์ ๊ณตํฉ๋๋ค."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# ์คํ
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
interface.launch()
|