Spaces:
Runtime error
Runtime error
File size: 4,871 Bytes
00ba432 764c078 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | ---
title: Vidya AI Tutor
emoji: π€
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 5.32.0
app_file: app.py
pinned: false
---
# Vidya V3 β Real-Time AI Tutor (Terminal POC)
A modular, terminal-based AI tutoring system powered by **Google Gemini** and
**Cognitive Apprenticeship (CA)** pedagogy. Zero UI, zero server β just Python
and a terminal.
---
## Architecture
```
vidya-realtime-ai-tutor/
βββ src/
β βββ main.py β entry point + REPL loop
β βββ config.py β env vars + constants
β βββ gemini_client.py β Gemini API (google-genai SDK)
β βββ tutor_session.py β per-turn orchestration
β βββ schemas.py β Pydantic input/output models
β βββ signal_extractor.pyβ local debug signal detector
β βββ phase_manager.py β fallback CA phase logic
β βββ utils.py β terminal colors + helpers
βββ prompts/
β βββ system_prompt.txt β Gemini's identity + rules
βββ logs/
β βββ conversations.json β auto-saved session logs
βββ requirements.txt
βββ .env.example
```
---
## Streamlit start
```bash
streamlit run streamlit_app.py
## Quickstart
```bash
# 1. Create and activate virtual environment
python -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activate
# 2. Install dependencies
pip install -r requirements.txt
# 3. Set up API key
copy .env.example .env # Windows
cp .env.example .env # macOS/Linux
# Edit .env and paste your Gemini API key:
# GEMINI_API_KEY=your_key_here
# 4. Run the tutor
python src/main.py
# Optional: enable debug signal view on startup
python src/main.py --debug
```
---
## Getting a Gemini API Key
1. Go to https://aistudio.google.com/app/apikey
2. Sign in with your Google account
3. Click **Create API key**
4. Paste it into your `.env` file
---
## Session Setup (one-time per run)
When you run the app you'll be asked:
| Question | Example inputs |
|---|---|
| Skill topic | `Python functions`, `SQL joins`, `OOP concepts` |
| Mastery level | `0.0` (beginner) β `1.0` (expert), e.g. `0.2` |
| Who are you? | `1` for student, `2` for service engineer |
| Starting phase | `1` MODEL, `2` COACH, `3` SCAFFOLD, `4` FADE |
| Language | `1` English, `2` Hindi, `3` Mixed |
---
## Demo Conversation (Python Functions, student, en)
```
You: I don't understand what a function is.
π Vidya [MODEL]
A function is a reusable block of code. Think of it like a recipe:
def greet(name):
return f"Hello, {name}!"
greet("Riya") β "Hello, Riya!"
The def keyword defines it; you call it by name.
π‘ Next: Try writing a function that adds two numbers.
You: Just tell me the answer.
π Vidya [COACH]
I'd love to help β but you'll learn much more by trying first!
What would the function signature look like? What inputs would it take?
π‘ Next: Start with: def add(a, b): and see what you can fill in.
You: Can you teach me cricket?
π Vidya [COACH]
That's a fun topic! But right now we're focused on Python functions β
and you're doing well! Let's stick with it. What part of functions
feels most unclear?
π‘ Next: Come back to Python functions β you're almost there!
You: exit
β
Conversation saved to logs/conversations.json (3 turns)
```
---
## Cognitive Apprenticeship Phases
| Phase | Tutor Behaviour |
|---|---|
| **MODEL** | Shows a worked example, thinks out loud |
| **COACH** | Asks guiding questions, no direct answers |
| **SCAFFOLD** | Partial hints, fills gaps not full solutions |
| **FADE** | Learner leads, tutor lightly nudges |
Gemini decides which phase to advance/hold/regress based on your responses.
---
## Debug Mode
Type `debug` at any point during the chat to toggle signal visibility:
```
[DEBUG] signals=confusion, answer_seeking | phase_reason=turn 3
```
Or start with `--debug` for it enabled from the first turn.
---
## Swapping LLM Provider
The Gemini call is isolated in `src/gemini_client.py`. To swap to OpenAI or
Anthropic Claude:
1. Open `src/gemini_client.py`
2. Replace the `call_gemini()` function body with your provider's SDK call
3. Keep the same function signature and return type (raw string)
4. Update `requirements.txt` with the new SDK
5. Add the new `*_API_KEY` to `.env.example`
`tutor_session.py`, `main.py`, and everything else stay unchanged.
---
## Log Format (`logs/conversations.json`)
```json
[
{
"config": { "skill_topic": "...", "mastery_level": 0.2, ... },
"final_phase": "COACH",
"turns": 5,
"conversation": [
{ "role": "user", "content": "..." },
{ "role": "assistant", "content": "..." }
]
}
]
```
---
## Requirements
- Python 3.10+
- Google Gemini API key (free tier available)
- Dependencies: `google-genai`, `python-dotenv`, `pydantic`
|