A FastAPI backend + Streamlit frontend geography guessing game powered by Google Street View. Players are shown Street View images and must click on a map to guess the location. Features JWT authentication, scoring system, and leaderboard.
- ๐ฎ 5-round gameplay with real-time scoring based on distance accuracy
- ๐ Interactive map powered by Folium with click-to-guess mechanics
- ๐ Secure authentication with JWT tokens and PBKDF2 hashing
- ๐บ๏ธ Google Street View imagery with smart on-demand caching
- ๐ Confetti animations on correct guesses
- ๐ก Subtle location hints - regional clues, not literal city names
- ๐ Leaderboard tracking top players
- ๐ฑ Responsive design with light-gray clean UI
- โก Efficient image caching - downloads only images that are played
- Backend: FastAPI, SQLAlchemy ORM, SQLite
- Frontend: Streamlit 1.51.0, Folium (interactive maps), streamlit-folium
- Authentication: OAuth2 with JWT tokens
- Hashing: PBKDF2-SHA256
- Images: Google Street View Static API (downloaded on-demand, cached locally)
- Python 3.8+
- Google Street View API key (free tier available at Google Cloud Console)
- Note: Requires billing enabled (but free tier covers ~1,000 images/month)
-
Clone the repository
git clone https://github.com/Adithya-Git05/Advanced-Python-Programming---Project.git cd Advanced-Python-Programming---Project -
Create virtual environment
python -m venv venv .\venv\Scripts\Activate.ps1 # Windows PowerShell # or source venv/bin/activate # macOS/Linux
-
Install dependencies
pip install -r requirements.txt
-
Setup environment variables
cp .env.example .env
Edit
.envand add your Google Street View API key:GOOGLE_STREETVIEW_KEY=your_api_key_here JWT_SECRET=your_secret_key_here BACKEND_URL=http://localhost:8000
# Terminal 1: Backend
.\venv\Scripts\Activate.ps1
uvicorn backend.main:app --host 0.0.0.0 --port 8000
# Terminal 2: Frontend
.\venv\Scripts\Activate.ps1
streamlit run frontend/app.py --server.port=8501# Terminal 1: Backend
source venv/bin/activate
uvicorn backend.main:app --host 0.0.0.0 --port 8000
# Terminal 2: Frontend
source venv/bin/activate
streamlit run frontend/app.py --server.port=8501- Open in browser
- Frontend: http://localhost:8501
- Backend API docs: http://localhost:8000/docs
- Register with a username and password (min 8 characters)
- Login with your credentials
- Start Game - You'll play 5 rounds
- View Street View image
- Click on the map where you think the location is
- Submit your guess - Get instant feedback on accuracy
- Earn points based on distance from actual location (max 5000 points)
- Check leaderboard to see top players
Points are calculated using exponential decay based on distance:
- Perfect guess (0m): 5,000 points
- 100m away: ~4,757 points
- 1km away: ~2,313 points
- 10km away: ~68 points
To minimize Google Street View API costs:
- On-demand caching: Images are downloaded only when a location is played for the first time
- Cached storage: Downloaded images are stored in
backend/cache/directory for future use - Zero subsequent API calls: Once cached, images are served locally with no additional API charges
- 40 locations available: 40 well-known cities are available for gameplay
This strategy means you only pay for images that are actually used during gameplay!
POST /register- Register new userPOST /token- Login and get JWT token
GET /random_location- Get random location with cached imagePOST /submit_guess- Submit location guessGET /leaderboard- Get top 10 players
GET /debug- View cached images and system info
See full API docs at http://localhost:8000/docs
Advanced-Python-Programming---Project/
โโโ backend/
โ โโโ main.py # FastAPI app, routes, game logic
โ โโโ app.db # SQLite database (auto-generated)
โ โโโ cache/ # Cached Google Street View images
โโโ frontend/
โ โโโ app.py # Streamlit UI
โโโ .env # Environment variables (create from .env.example)
โโโ .env.example # Template for .env
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
CREATE TABLE users (
id INTEGER PRIMARY KEY,
username VARCHAR UNIQUE NOT NULL,
hashed_password VARCHAR NOT NULL,
total_score INTEGER DEFAULT 0,
rounds_played INTEGER DEFAULT 0
);CREATE TABLE locations (
id INTEGER PRIMARY KEY,
name VARCHAR NOT NULL,
lat FLOAT NOT NULL,
lng FLOAT NOT NULL,
image_url VARCHAR,
image_filename VARCHAR
);GOOGLE_STREETVIEW_KEY- Your Google API key (required)JWT_SECRET- Secret for JWT tokens (change in production!)BACKEND_URL- Backend URL (default: http://localhost:8000)
MAX_POINTS- Maximum points per guess (default: 5000)SCORE_SCALE_METERS- Distance decay scale (default: 20000m)
- Verify your Google Street View API key is valid
- Check that billing is enabled on your Google Cloud project
- Ensure cache directory exists:
backend/cache/
- Restart both backend and frontend
- Delete
backend/app.dbto force re-seed
- Change ports in startup commands:
- Backend:
--port 8000 - Frontend:
--server.port 8501
- Backend:
- Real Street View image coverage (currently using fixed 40 locations)
- Multiplayer support with real-time guessing
- More map layers and satellite view option
- User profiles and statistics
- Custom game settings (rounds, difficulty, regions)
- Mobile responsive design improvements
Feel free to fork, modify, and share! Some ideas:
- Add more locations to seed
- Implement difficulty levels
- Create custom location sets
- Improve UI/UX
MIT License - feel free to use and modify for personal or educational purposes.
For issues or questions:
- Check the troubleshooting section above
- Verify all dependencies are installed:
pip install -r requirements.txt - Ensure Google API key has Street View Static API enabled
- Check that both backend and frontend are running
Enjoy the game! ๐
- This project is a demonstration and not secure for production as-is.
- Tokens are created without expiry for simplicity; in production add
expclaims and token refresh. - Keep your Google Street View API key and
JWT_SECRETsecure. - Use environment variables to manage secrets, never hardcode them.
- Add pagination and filtering to leaderboard
- Add per-round timing and better UX for map interactions
- Implement difficulty levels (easy/medium/hard based on regions)
- Add user profiles with gameplay statistics
- Improve mobile responsive design
- Add more location varieties across continents