suinY00N's picture
Create app.py
b8f6eea verified
raw
history blame contribute delete
884 Bytes
import gradio as gr
from transformers import pipeline
# ๊ฐ์„ฑ ๋ถ„์„ ํŒŒ์ดํ”„๋ผ์ธ ์ดˆ๊ธฐํ™”
sentiment = pipeline("sentiment-analysis")
# ์‚ฌ์šฉ์ž ์ž…๋ ฅ์— ๋Œ€ํ•œ ๊ฐ์„ฑ ๋ถ„์„ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜
def get_sentiment(์ž…๋ ฅ):
# ๊ฐ์„ฑ ๋ถ„์„ ์‹คํ–‰
result = sentiment(์ž…๋ ฅ)
# ๊ฒฐ๊ณผ ํฌ๋งทํŒ… ๋ฐ ๋ฐ˜ํ™˜
return result[0]
# Gradio ์•ฑ ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
iface = gr.Interface(
fn=get_sentiment, # ์‹คํ–‰ํ•  ํ•จ์ˆ˜
inputs=gr.inputs.Textbox(lines=2, placeholder="์—ฌ๊ธฐ์— ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”..."), # ์ž…๋ ฅ๋ž€ ์„ค์ •
outputs="json", # ์ถœ๋ ฅ ํ˜•ํƒœ
clear_on_submit=True, # ์ œ์ถœ ํ›„ ์ž…๋ ฅ๋ž€ ํด๋ฆฌ์–ด
title="ํ…์ŠคํŠธ ๊ฐ์„ฑ ๋ถ„์„", # UI ์ œ๋ชฉ
description="ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์ œ์ถœ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ ๊ฐ์„ฑ ๋ถ„์„ ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•˜์„ธ์š”." # UI ์„ค๋ช…
)
# Gradio ์•ฑ ์‹คํ–‰
iface.launch()