Download app.py from Tanseer45203/AI_lIFE_Experience_Chhatbot: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/Tanseer45203/AI_lIFE_Experience_Chhatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/Tanseer45203/AI_lIFE_Experience_Chhatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Tanseer45203/AI_lIFE_Experience_Chhatbot/resolve/main/app.py
1.8 kB
| 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( | |
| """ | |
| <style> | |
| body { font-size: 18px; } | |
| .stTextArea textarea { font-size: 16px !important; } | |
| .stButton button { font-size: 16px !important; padding: 10px; } | |
| </style> | |
| """, | |
| 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}") |