pip install transformers from transformers import pipeline # 감정 분류 파이프라인 생성 classifier = pipeline("text-classification", model="nlptown/bert-base-multilingual-uncased-sentiment") # 감정 분류 함수 정의 def classify_emotion(text): result = classifier(text)[0] label = result['label'] score = result['score'] return label, score # 일기 생성 함수 정의 def generate_diary(emotion): prompts = { "positive": "오늘은 정말 좋은 날이었어요. ", "negative": "오늘은 힘든 하루였어요. ", "neutral": "오늘은 그냥 평범한 하루였어요. " } prompt = prompts.get(emotion, "오늘은 기분이 복잡한 날이었어요. ") diary = prompt + "오늘의 일기를 마칩니다." return diary # 사용자 입력 받기 user_input = input("오늘의 감정을 한 문장으로 표현해주세요: ") # 감정 분류 emotion_label, _ = classify_emotion(user_input) # 감정 기반 일기 생성 diary = generate_diary(emotion_label) # 생성된 일기 출력 print("=== 생성된 일기 ===") print(diary)