
from transformers import pipeline
import gradio as gr
# Hugging Face의 pipeline을 사용하여 감정 분석 모델을 초기화합니다.
classifier = pipeline("sentiment-analysis")
# 감정 분석을 수행하는 함수를 정의합니다.
def sentiment_analysis(text):
result = classifier(text)
return result[0]["label"]
# Gradio 인터페이스를 설정합니다.
iface = gr.Interface(
fn=sentiment_analysis, # 위에서 정의한 함수를 사용합니다.
inputs=gr.Textbox(label="Input Text"), # 텍스트 입력 상자를 생성합니다.
outputs="json", # 출력 형태를 JSON으로 설정합니다.
examples=["I love this!", "I hate this."] # 예시 입력을 제공합니다.
)
# 인터페이스를 실행합니다.
iface.launch(share=True)
이 코드 실행하면 positive 이런 값이 안나오고 Error가 나옵니다.
