Commit ·
fdca18e
1
Parent(s): decd86c
Update README and Sidebar UI
Browse files- README.md +15 -129
- app.py +15 -29
- test_frontend.sh +19 -0
- test_hf_startup.sh +19 -0
README.md
CHANGED
|
@@ -1,45 +1,19 @@
|
|
| 1 |
-
-
|
| 2 |
-
title: FocusFlow
|
| 3 |
-
emoji: 🎯
|
| 4 |
-
colorFrom: purple
|
| 5 |
-
colorTo: indigo
|
| 6 |
-
sdk: docker
|
| 7 |
-
app_file: app.py
|
| 8 |
-
pinned: false
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
# FocusFlow - AI Study Companion
|
| 12 |
|
| 13 |
An intelligent study assistant powered by AI that transforms your learning materials into personalized, adaptive study experiences.
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
- ** RAG-Powered Q&A**: Ask questions and get answers with source citations
|
| 19 |
-
- ** Adaptive Quizzes**: Context-based quizzes that adapt to your performance
|
| 20 |
-
- ** Progress Tracking**: Track mastery levels and quiz history
|
| 21 |
-
- ** Smart Day Progression**: Automatically unlocks new topics as you complete them
|
| 22 |
-
- ** Source Citations**: Every answer cites the exact source and page number
|
| 23 |
-
- ** Cloud Persistence**: Study plans and progress persist across sessions (cloud demo only)
|
| 24 |
-
- ** Multi-User Support**: Each browser session maintains isolated data
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
> **Note**: The cloud demo uses ephemeral containers. Your data persists in Supabase but each browser tab is treated as a separate user. For true persistent local storage, use the local deployment below.
|
| 31 |
-
|
| 32 |
-
## Models Used
|
| 33 |
-
|
| 34 |
-
### Cloud Demo (HF Spaces)
|
| 35 |
-
- **LLM**: Meta-Llama-3-8B-Instruct (via Hugging Face Inference API)
|
| 36 |
-
- **Embeddings**: sentence-transformers/all-MiniLM-L6-v2
|
| 37 |
-
|
| 38 |
-
### Local Deployment
|
| 39 |
-
- **LLM**: llama3.2:1b (via Ollama - offline)
|
| 40 |
-
- **Embeddings**: nomic-embed-text (offline)
|
| 41 |
-
|
| 42 |
-
## Local Installation
|
| 43 |
|
| 44 |
### Prerequisites
|
| 45 |
- Python 3.10+
|
|
@@ -50,12 +24,12 @@ An intelligent study assistant powered by AI that transforms your learning mater
|
|
| 50 |
|
| 51 |
```bash
|
| 52 |
# Clone the repository
|
| 53 |
-
git clone https://github.com/
|
| 54 |
-
cd
|
| 55 |
|
| 56 |
# Create virtual environment
|
| 57 |
python -m venv venv
|
| 58 |
-
source venv/bin/activate # On Windows: venv\Scripts\activate
|
| 59 |
|
| 60 |
# Install dependencies
|
| 61 |
pip install -r requirements.txt
|
|
@@ -71,100 +45,12 @@ uvicorn backend.main:app --reload &
|
|
| 71 |
streamlit run app.py
|
| 72 |
```
|
| 73 |
|
| 74 |
-
Visit `http://localhost:8501` to use the app
|
| 75 |
-
|
| 76 |
-
## How to Use
|
| 77 |
-
|
| 78 |
-
1. **Upload PDFs**: Add your study materials in the Sources panel
|
| 79 |
-
2. **Generate Plan**: Ask the Calendar to create a study plan (e.g., "Make a 5-day plan")
|
| 80 |
-
3. **Study**: Click on topics to view lessons and ask questions
|
| 81 |
-
4. **Take Quizzes**: Test your knowledge and unlock new topics
|
| 82 |
-
5. **Track Progress**: View analytics and mastery levels
|
| 83 |
-
|
| 84 |
-
## Architecture
|
| 85 |
|
| 86 |
-
|
| 87 |
-
┌─────────────────────────────────────────┐
|
| 88 |
-
│ Streamlit Frontend │
|
| 89 |
-
│ (Material Design UI + Calendar) │
|
| 90 |
-
└──────────────┬──────────────────────────┘
|
| 91 |
-
│
|
| 92 |
-
┌───────▼────────┐
|
| 93 |
-
│ FastAPI │
|
| 94 |
-
│ Backend │
|
| 95 |
-
└───────┬────────┘
|
| 96 |
-
│
|
| 97 |
-
┌──────────┼──────────┐
|
| 98 |
-
│ │ │
|
| 99 |
-
┌───▼────┐ ┌──▼────┐ ┌──▼─────────┐
|
| 100 |
-
│ ChromaDB│ │ LLM │ │ Supabase │
|
| 101 |
-
│ (RAG) │ │ │ │ (Cloud DB)│
|
| 102 |
-
└─────────┘ └───────┘ └───────────┘
|
| 103 |
-
```
|
| 104 |
-
|
| 105 |
-
## Tech Stack
|
| 106 |
|
| 107 |
- **Frontend**: Streamlit + Material Design
|
| 108 |
- **Backend**: FastAPI + LangChain
|
| 109 |
- **Vector DB**: ChromaDB
|
| 110 |
- **LLM**: Ollama (local) / HuggingFace (cloud)
|
| 111 |
- **Database**: Supabase PostgreSQL (cloud) / JSON files (local)
|
| 112 |
-
|
| 113 |
-
## Cloud vs Local
|
| 114 |
-
|
| 115 |
-
| Feature | Local | Cloud (HF Spaces) |
|
| 116 |
-
|---------|-------|-------------------|
|
| 117 |
-
| **Privacy** | Fully offline | Data in cloud |
|
| 118 |
-
| **Cost** | Free | Free |
|
| 119 |
-
| **Speed** | Depends on hardware | Fast |
|
| 120 |
-
| **Persistence** | Local files | Supabase DB |
|
| 121 |
-
| **Setup** | Requires Ollama | Just click |
|
| 122 |
-
| **Multi-user** | Single user | Multi-user |
|
| 123 |
-
|
| 124 |
-
## Configuration
|
| 125 |
-
|
| 126 |
-
### Environment Variables
|
| 127 |
-
|
| 128 |
-
For cloud deployment, set these in Hugging Face Spaces Settings:
|
| 129 |
-
|
| 130 |
-
```bash
|
| 131 |
-
# Required for cloud mode
|
| 132 |
-
HUGGINGFACE_API_TOKEN=your_hf_token
|
| 133 |
-
SUPABASE_URL=your_supabase_url
|
| 134 |
-
SUPABASE_KEY=your_supabase_key
|
| 135 |
-
USE_SUPABASE=true
|
| 136 |
-
LLM_PROVIDER=huggingface
|
| 137 |
-
```
|
| 138 |
-
|
| 139 |
-
For local deployment, no configuration needed!
|
| 140 |
-
|
| 141 |
-
## Privacy
|
| 142 |
-
|
| 143 |
-
- **Local Mode**: All data stays on your machine. No internet required.
|
| 144 |
-
- **Cloud Mode**: Study plans stored in Supabase. PDFs processed in-memory, not stored.
|
| 145 |
-
|
| 146 |
-
## License
|
| 147 |
-
|
| 148 |
-
MIT License - See [LICENSE](LICENSE) for details.
|
| 149 |
-
|
| 150 |
-
## Contributing
|
| 151 |
-
|
| 152 |
-
Contributions welcome! Please feel free to submit a Pull Request.
|
| 153 |
-
|
| 154 |
-
## Contact
|
| 155 |
-
|
| 156 |
-
For questions or feedback, open an issue on [GitHub](https://github.com/thesivarohith/hack/issues).
|
| 157 |
-
|
| 158 |
-
---
|
| 159 |
-
|
| 160 |
-
**Built with for better learning experiences**
|
| 161 |
-
|
| 162 |
-
**Links:**
|
| 163 |
-
- [Live Demo](https://huggingface.co/spaces/SivaRohith69/focusflow)
|
| 164 |
-
|
| 165 |
-
## 🚀 Latest Updates
|
| 166 |
-
- ✅ Firebase Authentication (Google, GitHub, Email/Password)
|
| 167 |
-
- ✅ OCR support for scanned PDFs
|
| 168 |
-
- ✅ Paste Text feature for cloud mode
|
| 169 |
-
- ✅ Student data stored in Supabase per user
|
| 170 |
-
- ✅ Deployed on HuggingFace Spaces
|
|
|
|
| 1 |
+
# FocusFlow - AI Study Companion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
An intelligent study assistant powered by AI that transforms your learning materials into personalized, adaptive study experiences.
|
| 4 |
|
| 5 |
+
[Try FocusFlow on Hugging Face Spaces](https://huggingface.co/spaces/noodledom/focusflow)
|
| 6 |
|
| 7 |
+
## Features
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
- **Multi-Subject Study Planning**: Upload PDFs and get automated multi-day study plans.
|
| 10 |
+
- **RAG-Powered Q&A**: Ask questions and get answers with source citations.
|
| 11 |
+
- **Adaptive Quizzes**: Context-based quizzes that adapt to your performance.
|
| 12 |
+
- **Progress Tracking**: Track mastery levels and quiz history.
|
| 13 |
+
- **Cloud Persistence**: Study plans and progress persist across sessions.
|
| 14 |
+
- **Multi-User Support**: Firebase Authentication enables secure, isolated data per user.
|
| 15 |
|
| 16 |
+
## Local Installation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
### Prerequisites
|
| 19 |
- Python 3.10+
|
|
|
|
| 24 |
|
| 25 |
```bash
|
| 26 |
# Clone the repository
|
| 27 |
+
git clone https://github.com/suwethadevakiruba3012-wq/Free.git
|
| 28 |
+
cd Free
|
| 29 |
|
| 30 |
# Create virtual environment
|
| 31 |
python -m venv venv
|
| 32 |
+
source venv/bin/activate # On Windows: venv\\Scripts\\activate
|
| 33 |
|
| 34 |
# Install dependencies
|
| 35 |
pip install -r requirements.txt
|
|
|
|
| 45 |
streamlit run app.py
|
| 46 |
```
|
| 47 |
|
| 48 |
+
Visit `http://localhost:8501` to use the app.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
## Tech Stack
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
- **Frontend**: Streamlit + Material Design
|
| 53 |
- **Backend**: FastAPI + LangChain
|
| 54 |
- **Vector DB**: ChromaDB
|
| 55 |
- **LLM**: Ollama (local) / HuggingFace (cloud)
|
| 56 |
- **Database**: Supabase PostgreSQL (cloud) / JSON files (local)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -541,39 +541,25 @@ if not st.session_state.get("logged_in") and not st.session_state.get("local_byp
|
|
| 541 |
show_login_page()
|
| 542 |
st.stop()
|
| 543 |
|
| 544 |
-
# Show sign out
|
| 545 |
with st.sidebar:
|
| 546 |
name = st.session_state.get("user_name", "Student")
|
| 547 |
email = st.session_state.get("user_email", "")
|
| 548 |
avatar = st.session_state.get("user_avatar", "")
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
if st.button("⚠️ Admin: Reset All Data", help="Wipes all existing backend data to fix shared state issues", type="primary"):
|
| 564 |
-
with st.spinner("Wiping all existing data..."):
|
| 565 |
-
try:
|
| 566 |
-
res = requests.delete(f"{API_URL}/admin/clear_all_data?secret=focusflow_clear", timeout=10)
|
| 567 |
-
if res.status_code == 200:
|
| 568 |
-
st.success("✅ All legacy data wiped successfully! Please refresh.")
|
| 569 |
-
time.sleep(2)
|
| 570 |
-
for k in list(st.session_state.keys()):
|
| 571 |
-
del st.session_state[k]
|
| 572 |
-
st.rerun()
|
| 573 |
-
else:
|
| 574 |
-
st.error(f"Failed: {res.text}")
|
| 575 |
-
except Exception as e:
|
| 576 |
-
st.error(f"Error resetting data: {e}")
|
| 577 |
st.divider()
|
| 578 |
|
| 579 |
# Session State
|
|
|
|
| 541 |
show_login_page()
|
| 542 |
st.stop()
|
| 543 |
|
| 544 |
+
# Show profile and sign out in sidebar
|
| 545 |
with st.sidebar:
|
| 546 |
name = st.session_state.get("user_name", "Student")
|
| 547 |
email = st.session_state.get("user_email", "")
|
| 548 |
avatar = st.session_state.get("user_avatar", "")
|
| 549 |
+
|
| 550 |
+
with st.popover("👤 Profile"):
|
| 551 |
+
if avatar:
|
| 552 |
+
st.image(avatar, width=50)
|
| 553 |
+
st.markdown(f"**{name}**")
|
| 554 |
+
st.caption(email)
|
| 555 |
+
if st.button("🚪 Sign Out", use_container_width=True):
|
| 556 |
+
for k in ["uid", "user_email", "user_name", "user_avatar",
|
| 557 |
+
"logged_in", "firebase_token", "local_bypass",
|
| 558 |
+
"user_info", "profile_loaded", "study_plan",
|
| 559 |
+
"topic_scores", "mastery_data", "chat_history"]:
|
| 560 |
+
st.session_state.pop(k, None)
|
| 561 |
+
st.rerun()
|
| 562 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
st.divider()
|
| 564 |
|
| 565 |
# Session State
|
test_frontend.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
export HF_HUB_OFFLINE=0
|
| 4 |
+
export TRANSFORMERS_OFFLINE=1
|
| 5 |
+
export USE_SUPABASE=true
|
| 6 |
+
export LLM_PROVIDER=huggingface
|
| 7 |
+
|
| 8 |
+
echo "Starting frontend..."
|
| 9 |
+
streamlit run app.py --server.port 7860 --server.address 0.0.0.0 --server.headless true > frontend.log 2>&1 &
|
| 10 |
+
FRONTEND_PID=$!
|
| 11 |
+
sleep 5
|
| 12 |
+
|
| 13 |
+
if ps -p $FRONTEND_PID > /dev/null; then
|
| 14 |
+
echo "Frontend is running fine."
|
| 15 |
+
kill $FRONTEND_PID
|
| 16 |
+
else
|
| 17 |
+
echo "Frontend CRASHED! Logs:"
|
| 18 |
+
cat frontend.log
|
| 19 |
+
fi
|
test_hf_startup.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
export HF_HUB_OFFLINE=0
|
| 4 |
+
export TRANSFORMERS_OFFLINE=1
|
| 5 |
+
export USE_SUPABASE=true
|
| 6 |
+
export LLM_PROVIDER=huggingface
|
| 7 |
+
|
| 8 |
+
echo "Starting backend..."
|
| 9 |
+
python3 -m uvicorn backend.main:app --host 0.0.0.0 --port 8000 > backend.log 2>&1 &
|
| 10 |
+
BACKEND_PID=$!
|
| 11 |
+
sleep 5
|
| 12 |
+
|
| 13 |
+
if ps -p $BACKEND_PID > /dev/null; then
|
| 14 |
+
echo "Backend is running fine."
|
| 15 |
+
kill $BACKEND_PID
|
| 16 |
+
else
|
| 17 |
+
echo "Backend CRASHED! Logs:"
|
| 18 |
+
cat backend.log
|
| 19 |
+
fi
|