The Python Sage is an interactive, AI-powered tutor designed to help users master Python concepts. Leveraging Google's Gemini Pro model, this application transforms the official Python tutorial documentation into dynamic quizzes, code challenges, and in-depth reviews. It features a unique voice-activated follow-up system, allowing users to ask questions and get instant clarification via audio.
- Multiple Learning Modes: Choose from three distinct modes:
- Complete Section Review: Get a detailed, point-by-point explanation of every concept in a topic, complete with definitions and code examples.
- Concept-by-Concept Code Challenges: Generate a series of targeted coding exercises for each concept within a topic.
- 1 Comprehensive Code Challenge: Tackle a single, multi-step capstone problem that integrates multiple concepts from the selected topic.
- Adjustable Difficulty: Tailor the content to your skill level, from "Infant" for absolute beginners to "PHD" for seasoned experts.
- Voice-Activated Follow-ups: After generating a quiz, use the built-in audio recorder to ask clarifying questions about the material. The AI will provide a concise, context-aware answer.
- Comprehensive Content: Covers a wide range of topics sourced directly from the official Python 3 tutorial documentation.
- Secure and Private: Your Google API key is processed exclusively in-session and is never stored or logged.
- Slick, Responsive UI: A clean, two-column layout with a sticky follow-up column for a seamless desktop experience. The UI intelligently adapts, hiding advanced features until an API key is provided.
You can try the live application here:
The repository is organized to be simple and maintainable:
.
├── .gitignore # Ensures sensitive files and artifacts are not committed.
├── app.py # The main Streamlit application script.
├── audio_follow_up.py # A modular component for the audio recorder and follow-up logic.
├── python_sage_demo.mp4 # The video file used for the welcome screen demo.
├── python_tutorial_library.json # A JSON file containing the pre-processed Python tutorial content.
└── requirements.txt # A list of all necessary Python packages for the project.
Follow these steps to get The Python Sage running on your local machine.
Open your terminal or command prompt and run the following command:
git clone <your-repository-url>
cd <repository-folder-name>
It is highly recommended to use a virtual environment to manage project dependencies.
# For Windows
python -m venv .venv
.venv\Scripts\activate
# For macOS / Linux
python3 -m venv .venv
source .venv/bin/activate
Install all the required packages using the requirements.txt
file.
pip install -r requirements.txt
This application requires a Google API key to interact with the Gemini model.
- Go to the Google AI Studio.
- Sign in with your Google account.
- Click on the "Create API key in new project" button.
- Copy the generated key. You will paste this into the application's sidebar.
Once the setup is complete, run the following command in your terminal from the project's root directory:
streamlit run app.py
Your web browser should automatically open with the application running.
- Enter Your API Key: On the left sidebar, paste your Google API Key into the designated input field. The main application interface will appear.
- Select a Topic: Choose a Python topic you want to learn about from the "Choose a topic" dropdown menu.
- Select a Quiz Mode: Use the radio buttons to select your preferred learning mode (e.g., "Complete Section Review").
- Select a Difficulty: Adjust the slider to match your current knowledge level.
- Generate Quiz: Click the "✨ Generate My Quiz!" button. The main content area will populate with the AI-generated material.
- Ask a Follow-up Question:
- In the right-hand column, click the microphone icon in the "Ask a Follow-up" section.
- Record your question about the content on the left.
- Stop the recording. The app will process your audio and display a text-based answer from the AI below the recorder.
Security and user privacy are top priorities.
- API Key Handling: Your Google API key is never stored by the application. It is only held in the server's memory for the duration of your session and is immediately discarded when you close the browser tab. The input field is of
type="password"
to mask it from shoulder-surfers. - No Prompt Injection Risk: The application's prompts are constructed from trusted, hard-coded templates and predefined user selections (dropdowns, sliders). Raw user text is not formatted into the prompts, mitigating the risk of prompt injection attacks.
- Secure Configuration: The
.gitignore
file is configured to explicitly ignore sensitive files, including virtual environments (.venv
), environment variable files (.env
), and Streamlit's secret management file (.streamlit/secrets.toml
), preventing accidental credential exposure.
Contributions are welcome! If you have ideas for new features, find a bug, or want to improve the documentation, please feel free to:
- Open an issue to discuss the change.
- Fork the repository.
- Create a new branch for your feature (
git checkout -b feature/AmazingFeature
). - Commit your changes (
git commit -m 'Add some AmazingFeature'
). - Push to the branch (
git push origin feature/AmazingFeature
). - Open a Pull Request.
- The tutorial content is based on the official Python 3 Documentation.
- Built with the amazing Streamlit framework.
- Powered by Google's Gemini API.