This project provides a web-based frontend for the SheCounts financial literacy chatbot, built with HTML/JavaScript frontend and Python Flask backend.
chatbots code/
├── chatbot_code_template.py # Original Streamlit chatbot
├── chatbot_backend.py # Flask API backend
├── requirements.txt # Python dependencies
├── setup_chatbot.py # Setup script
└── README.md # This file
Root directory/
└── chatbot_frontend.html # HTML frontend
- Interactive Chat Interface: Clean, responsive web interface
- AI-Powered Questions: Generate random financial literacy questions using Google Gemini
- Answer Evaluation: Automatic evaluation of user responses
- Resource Recommendations: Relevant financial resources from Pinecone database
- Real-time Chat: Seamless conversation flow with the AI assistant
- Python 3.7 or higher
- Google Gemini API key
- Pinecone API key (optional, for resource recommendations)
-
Navigate to the chatbots code directory:
cd "chatbots code"
-
Run the setup script:
python setup_chatbot.py
-
Configure API keys in
chatbot_backend.py:- Replace
YOUR_API_KEY_HEREwith your Google Gemini API key - Replace
YOUR_PINECONE_API_KEY_HEREwith your Pinecone API key
- Replace
-
Install requirements:
pip install -r requirements.txt
-
Create templates folder:
mkdir templates cp ../chatbot_frontend.html templates/
-
Configure API keys in
chatbot_backend.py
-
Start the Flask backend:
python chatbot_backend.py
-
Open your browser to: http://localhost:5000
For development or testing, you can also run the original Streamlit version:
streamlit run chatbot_code_template.pyThe Flask backend provides the following REST API endpoints:
POST /api/generate_question- Generate a new questionPOST /api/submit_answer- Submit and evaluate an answerPOST /api/ask_question- Ask a general questionPOST /api/reset_chat- Reset the chat session
- Visit Google AI Studio
- Create a new API key
- Copy the key to
chatbot_backend.py
- Visit Pinecone
- Create an account
- Get your API key from the dashboard
- Copy the key to
chatbot_backend.py
Modify the generate_question() function in chatbot_backend.py to include new topics:
def generate_question(self, topic="your_new_topic"):
question_instruction = f"Generate a question about {topic}..."Edit the CSS in chatbot_frontend.html to customize the appearance:
- Colors, fonts, and layout in the
<style>section - Responsive design breakpoints
- Chat bubble styling
Update your Pinecone database with new financial literacy resources, or modify the get_relevant_resource() function to use different data sources.
-
API Key Errors
- Ensure API keys are correctly set in
chatbot_backend.py - Check that your API keys have the necessary permissions
- Ensure API keys are correctly set in
-
Pinecone Connection Issues
- Verify your Pinecone API key and index name
- The app will still work without Pinecone (resources won't be shown)
-
Port Already in Use
- Change the port in
chatbot_backend.py:app.run(port=5001) - Update the API_BASE_URL in the frontend accordingly
- Change the port in
-
CORS Issues
- Ensure Flask-CORS is installed:
pip install flask-cors - Check that CORS is properly configured in the backend
- Ensure Flask-CORS is installed:
- Use browser developer tools to monitor API calls
- Check Flask console for backend error messages
- Test API endpoints individually using tools like Postman
The frontend is designed to integrate seamlessly with the existing SheCounts website:
- Uses the same styling and navigation structure
- Matches the existing color scheme and fonts
- Includes the site header and navigation menu
To integrate:
- Update navigation links in other pages to point to the chatbot
- Ensure consistent styling across all pages
- Test the mobile responsiveness
- User authentication and progress tracking
- Multiple chatbot topics/specializations
- Voice input/output capabilities
- Integration with learning management systems
- Analytics and reporting features
For issues or questions:
- Check this README for common solutions
- Review the Flask and browser console logs
- Verify your API keys and network connectivity
- Test with the Streamlit version to isolate issues