import gradio as gr from transformers import pipeline # 1. 사전학습된 감정 분석 파이프라인 로드 sentiment_pipeline = pipeline("sentiment-analysis") # 2. 예측 함수 정의 def analyze_sentiment(text): results = sentiment_pipeline(text) return results # 3. Gradio UI 구성 # - inputs: 텍스트 입력 # - outputs: 결과(JSON 형식 표시) demo = gr.Interface( fn=analyze_sentiment, inputs=gr.Textbox(lines=3, placeholder="텍스트를 입력하세요"), outputs="json", title="감정 분석 데모", description="Hugging Face Transformers의 파이프라인을 사용해 감정(긍정/부정)을 예측합니다." ) # 4. 실행 if __name__ == "__main__": demo.launch()