import gradio as gr
import pandas as pd
import random
from transformers import pipeline, Conversation
--- Módulo de Análise de Sentimentos (simples exemplo) ---
def analisar_sentimento(texto):
if any(p in texto.lower() for p in ["feliz", "alegre", "animado"]):
return "positivo"
elif any(p in texto.lower() for p in ["triste", "deprimido", "cansado"]):
return "negativo"
else:
return "neutro"
--- Módulo de Recomendação ---
def recomendar_musicas(sentimento):
recomendacoes = {
"positivo": ["Happy - Pharrell Williams", "Good Vibrations - Beach Boys"],
"negativo": ["Fix You - Coldplay", "Someone Like You - Adele"],
"neutro": ["Imagine - John Lennon", "Let It Be - Beatles"]
}
return recomendacoes.get(sentimento, ["Nenhuma recomendação disponível"])
--- Módulo de Chatbot Integrado ---
def chatbot_resposta(mensagem, historico):
sentimento = analisar_sentimento(mensagem)
musicas = recomendar_musicas(sentimento)
resposta = f"Detectei que você está com um sentimento {sentimento}.\n"
f"Recomendo ouvir: {', '.join(musicas)}.\n"
f"Quer conversar mais sobre isso?"
historico.append((mensagem, resposta))
return historico, historico
--- Interface Gradio ---
with gr.Blocks() as demo:
gr.Markdown(" Playcatch - Música e Emoções")
chatbot = gr.Chatbot()
msg = gr.Textbox(label="Digite sua mensagem")
clear = gr.Button("Limpar conversa")
def limpar():
return [], []
msg.submit(chatbot_resposta, [msg, chatbot], [chatbot, chatbot])
clear.click(limpar, None, [chatbot, chatbot])
demo.launch()