This project is a full-stack Google Chrome extension that simplifies highlighted text on any webpage. It uses a JavaScript frontend to capture text, a Python (Flask) backend to handle API requests, and the Google Gemini API to generate the simplified text.
This application is built with a classic client-server architecture:
- Frontend (Chrome Extension): The user highlights text on a webpage and clicks the extension icon. The
popup.jsscript injects a content script to get the selected text. - API Call: The extension's
popup.jssends the highlighted text to a local Flask backend (http://127.0.0.1:5000/simplify) using afetchPOST request. - Backend (Flask Server): The Flask server (
app.py) receives the text. It then constructs a prompt and makes a secure, server-to-server request to the Google Gemini API, using a hidden API key from a.envfile. - Response: The Gemini API returns the simplified text. The Flask server passes this response back to the Chrome extension, which displays it to the user in the popup window.
- Frontend (Client):
- HTML5
- CSS3
- JavaScript (ES6+)
- Chrome Extension API (Manifest V3)
- Backend (Server):
- Python
- Flask (for the web server and API)
- Google Gemini API (gemini-pro)
flask-cors(to handle requests from the extension)python-dotenv(for secure API key management)
- Other:
- Git & GitHub
venv(Python virtual environment)
To run this project on your local machine, you will need to run the frontend and backend separately.
-
Navigate to the
backend-serverdirectory:cd backend-server -
Create and activate a Python virtual environment:
# Create python3 -m venv venv # Activate (macOS/Linux) source venv/bin/activate
-
Install the required dependencies:
pip install -r requirements.txt
(Note: You may need to create a
requirements.txtfile first by runningpip freeze > requirements.txt) -
Create a
.envfile in thebackend-serverfolder and add your Gemini API key:GEMINI_API_KEY=your_gemini_api_key_hereNote: Get your API key from Google AI Studio.
-
Run the server:
python app.py
The server will start on
http://127.0.0.1:5000.
- Open Google Chrome.
- Navigate to the extensions page:
chrome://extensions. - Enable "Developer mode" in the top-right corner.
- Click the "Load unpacked" button.
- Select the entire
extension-frontendfolder from this project. - The extension will appear in your toolbar. You can now use it on any webpage!