test0422 / app.py
grimzaeye's picture
Update app.py
6162193 verified
raw
history blame
1.08 kB
# 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()