import streamlit as st
import requests
import json
from datetime import datetime
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Configuration
BACKEND_URL = os.getenv("BACKEND_URL", "http://localhost:8000")
# Page configuration
st.set_page_config(
page_title="CultureBot - Your AI Cultural Guide",
page_icon="đ",
layout="wide",
initial_sidebar_state="expanded"
)
# Custom CSS for beautiful styling
st.markdown("""
""", unsafe_allow_html=True)
# Sidebar with app information
with st.sidebar:
st.markdown("""
""", unsafe_allow_html=True)
st.markdown("---")
# Navigation
st.markdown("### đ§ Navigation")
page = st.selectbox(
"Choose a page:",
["đ Home", "đŦ Chat with CultureBot", "đ Cultural Facts", "âšī¸ About"],
key="navigation"
)
st.markdown("---")
# Quick stats
st.markdown("### đ Quick Stats")
try:
response = requests.get(f"{BACKEND_URL}/health", timeout=5)
if response.status_code == 200:
st.success("đĸ Backend Online")
else:
st.error("đ´ Backend Offline")
except:
st.error("đ´ Backend Offline")
# Random fact
st.markdown("### đ˛ Random Fact")
if st.button("Get Random Fact"):
try:
response = requests.get(f"{BACKEND_URL}/facts/random", timeout=10)
if response.status_code == 200:
fact = response.json()
st.markdown(f"""
Welcome to CultureBot
Your AI-powered guide to understanding cultures, traditions, and social customs from around the world
""", unsafe_allow_html=True)
# Feature cards
col1, col2, col3 = st.columns(3)
with col1:
st.markdown("""
Chat with CultureBot
Ask me about any culture, country, or tradition!
""", unsafe_allow_html=True)
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat messages
for message in st.session_state.messages:
if message["role"] == "user":
st.markdown(f"""
Cultural Facts Explorer
Browse our curated collection of cultural insights
""", unsafe_allow_html=True)
# Filters
col1, col2 = st.columns(2)
with col1:
country_filter = st.selectbox(
"Filter by Country:",
["All Countries", "Japan", "India", "Brazil", "Germany", "China", "France", "South Korea", "Mexico", "Egypt", "Russia", "Thailand", "Italy"]
)
with col2:
category_filter = st.selectbox(
"Filter by Category:",
["All Categories", "etiquette", "business", "greeting", "food", "language", "family", "beliefs", "general"]
)
# Fetch and display facts
try:
if country_filter != "All Countries":
response = requests.get(f"{BACKEND_URL}/facts/country/{country_filter}", timeout=10)
elif category_filter != "All Categories":
response = requests.get(f"{BACKEND_URL}/facts/category/{category_filter}", timeout=10)
else:
# Get random facts for display
facts = []
for _ in range(10):
fact_response = requests.get(f"{BACKEND_URL}/facts/random", timeout=5)
if fact_response.status_code == 200:
facts.append(fact_response.json())
for fact in facts:
st.markdown(f"""
About CultureBot
Bridging cultures through AI-powered conversations
""", unsafe_allow_html=True)
# Mission and features
col1, col2 = st.columns(2)
with col1:
st.markdown("""
### đ¯ Our Mission
CultureBot was created to help people understand and appreciate the rich diversity of cultures around the world.
In our increasingly connected world, cultural awareness is more important than ever.
### đ§ Technology Stack
- **Frontend**: Streamlit (Python)
- **Backend**: FastAPI (Python)
- **AI Engine**: OpenAI GPT-3.5-turbo
- **Database**: In-memory cultural facts database
""")
with col2:
st.markdown("""
### ⨠Features
- **Global Coverage**: Cultural insights from countries across all continents
- **AI-Powered Chat**: Natural conversation interface powered by OpenAI
- **Curated Content**: Carefully researched and verified cultural facts
- **Smart Responses**: Context-aware answers tailored to your questions
- **Real-time Interaction**: Fast and responsive chat experience
""")
st.markdown("---")
# Technical details
st.markdown("### đī¸ Architecture")
st.markdown("""
CultureBot follows a modern microservices architecture:
1. **Streamlit Frontend**: Beautiful, interactive user interface
2. **FastAPI Backend**: High-performance API server
3. **OpenAI Integration**: Advanced natural language processing
4. **Cultural Database**: Curated collection of cultural facts and insights
""")
# Contact and support
st.markdown("### đ Support")
st.markdown("""
For technical support or cultural content suggestions, please contact:
- **Team**: Cultural AI Labs
- **Version**: 2.1.0
- **Last Updated**: January 15, 2024
""")