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()