import os import streamlit as st from groq import Groq from dotenv import load_dotenv # Load API key load_dotenv() API_KEY = os.getenv("GROQ_API_KEY") # Initialize Groq client client = Groq(api_key=API_KEY) # Streamlit App Title st.set_page_config(page_title="Life Experience Chatbot", layout="centered") st.title("🌍 AI Life Experience Chatbot") # Styling for mobile responsiveness st.markdown( """ """, unsafe_allow_html=True, ) # List of Life Topics life_topics = [ "Police Life", "Student Life", "Engineer Life", "Doctor Life", "Shopkeeper Life", "Labour Life", "Freeman Life", "Hostel Life", "Home Life", "Karachi Life", "Islamabad Life", "Tharimirwah Life", "Khairpur Life", "Pith Ghoth Life", "Sukkur Life", "Ghotki Life", "Rancour Life", "Pakistan Life", "Qatar Life", "Saudi Life", "Iron Life" ] # Select a Topic selected_life = st.selectbox("Choose a Life Experience to Explore:", life_topics) # User Input for Customization user_input = st.text_area("Ask about this lifestyle (optional):", placeholder="E.g., 'What challenges do police officers face?'") # Generate AI Response Button if st.button("Get AI Insight"): user_prompt = f"Describe the lifestyle of {selected_life}. {user_input if user_input else ''}" try: response = client.chat.completions.create( model="llama-3.3-70b-versatile", messages=[{"role": "user", "content": user_prompt}] ) st.write("### 📝 AI-Generated Insight:") st.write(response.choices[0].message.content) except Exception as e: st.error(f"Error: {e}")