Ezhil
repo init
601d457
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})*")