import os import streamlit as st from datetime import datetime from dotenv import load_dotenv from groq_api import chat_with_groq # Load environment variables load_dotenv() # Streamlit UI Setup st.set_page_config(page_title="Spotify Songs Chatbot", layout="wide") # Title with Spotify-related emojis st.title("šŸŽµ Spotify Songs Chatbot šŸŽ¶") st.write("Ask me about songs, artists, or playlists! šŸŽ§") # Chat memory if "messages" not in st.session_state: st.session_state.messages = [ {"role": "assistant", "content": "Hello! I’m a Spotify Songs Chatbot. I can help you find songs, artists, or playlists for you. What would you like to know? šŸŽ§", "timestamp": datetime.now().strftime("%H:%M")} ] # Display chat history using st.chat_message for msg in st.session_state.messages: with st.chat_message(msg["role"], avatar=("šŸ‘¦šŸ»" if msg["role"] == "user" else "šŸŽ¤")): content = msg["content"] timestamp = msg.get("timestamp", datetime.now().strftime("%H:%M")) st.markdown(f"{content} \n*({timestamp})*") # User input field using st.chat_input user_input = st.chat_input( "Ask me about songs, artists, playlists! šŸŽø" ) # Handle input submission if user_input: timestamp = datetime.now().strftime("%H:%M") # Add user message to chat st.session_state.messages.append( {"role": "user", "content": user_input, "timestamp": timestamp} ) with st.chat_message("user", avatar="šŸ‘¦šŸ»"): st.markdown(f"{user_input} \n*({timestamp})*") # Get bot response bot_reply = chat_with_groq(user_input) st.session_state.messages.append( {"role": "assistant", "content": bot_reply, "timestamp": timestamp} ) with st.chat_message("assistant", avatar="šŸŽ¤"): st.markdown(f"{bot_reply} \n*({timestamp})*")