def analyze_sentiment()

in text-classification/code/main.py [0:0]


def analyze_sentiment():
    if not request.is_json:
        return jsonify({"error": "Request must be JSON"}), 400

    data = request.get_json()
    if "text" not in data:
        return jsonify({"error": "Missing 'text' in request data"}), 400
    
    text = data["text"]
    
    prompt = f"""Classify the emotion in this sentence "{text}". Give me a simple answer in only one word small letters nothing else such as happy, sad, angry, doubtful, thoughtful, kind, stressed. Refrain from explaining your answer"""
    

    emotion = get_chat_response(chat, prompt).split()[0]   
    return insert_emotion_in_bigquery(emotion, text)