File size: 1,083 Bytes
6162193 46e166c 0a63990 46e166c 6162193 0a63990 6162193 46e166c 6162193 46e166c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# import gradio as gr
# from transformers import pipeline
# sentiment = pipeline('sentiment-analysis')
# # def get_sentiment(input):
# # response =
# def greet(name):
# return "Hello " + name + "!!"
# iface = gr.Interface(fn=greet, title="Sentiment Analysis", inputs="text", outputs="text")
# iface.launch()
import gradio as gr
from transformers import pipeline
# Hugging Face์์ ์ ๊ณตํ๋ sentiment-analysis ํ์ดํ๋ผ์ธ ๋ก๋
sentiment = pipeline('sentiment-analysis')
# ์
๋ ฅ ํ
์คํธ์ ๋ํด ๊ฐ์ ๋ถ์์ ์ํํ๋ ํจ์
def get_sentiment(input_text):
# sentiment-analysis ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์
๋ ฅ ๋ฐ์ ํ
์คํธ์ ๊ฐ์ ์ ๋ถ์
result = sentiment(input_text)
# ๊ฒฐ๊ณผ๋ ๋ฆฌ์คํธ ํํ๋ก ๋ฐํ๋๋ฉฐ, ์ฒซ ๋ฒ์งธ ๊ฒฐ๊ณผ์ ๋ ์ด๋ธ๊ณผ ์ ์๋ฅผ ํฌ๋งทํ
ํ์ฌ ๋ฐํ
return f"Label: {result[0]['label']}, Score: {result[0]['score']:.2f}"
# Gradio ์ธํฐํ์ด์ค ์ค์
iface = gr.Interface(fn=get_sentiment, title="Sentiment Analysis", inputs="text", outputs="text")
# ์ธํฐํ์ด์ค ์คํ
iface.launch() |