This project is a full-stack web application that uses React for the frontend and Flask for the backend. The app allows users to submit a URL, scrapes the content, generates questions based on the content using OpenAI's GPT API, and categorizes users based on their answers.

- Features
- Tech Stack
- Setup Instructions
- Usage
- Project Structure
- API Documentation
- Testing
- Troubleshooting
- Contributing
- License
- Scrapes content from a provided URL.
- Uses OpenAI GPT API to generate dynamic questions based on content.
- Presents questions to the user and categorizes them based on answers.
- Mock responses available for testing without consuming OpenAI quota.
- Frontend: React, Axios
- Backend: Flask, Flask-CORS, BeautifulSoup, OpenAI API
- Libraries: Python, Node.js
- Third-Party Services: OpenAI GPT API
- Python 3.x
- Node.js and npm
- OpenAI API key
-
Clone the repository and navigate to the
flask-backenddirectory:git clone <repo_url> cd react-flask-app/flask-backend
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.envfile in theflask-backenddirectory and add your OpenAI API key:OPENAI_API_KEY=your_openai_api_key -
Start the Flask server:
python app.py
-
Navigate to the
react-frontenddirectory:cd ../react-frontend -
Install dependencies:
npm install
-
Start the React development server:
npm start
The React app should now be running at http://localhost:3000, and the Flask API server should be running at http://localhost:5000.
- Open the React app in your browser at
http://localhost:3000. - Enter a URL in the input field and submit.
- The backend will scrape the content, generate questions, and display them in the app.
- Select answers to the questions and submit to view your categorized result.
react-flask-app/
├── flask-backend/
│ ├── app.py # Flask API setup and route handlers
│ ├── requirements.txt # Python dependencies for Flask
│ ├── .env # Environment variables (not in repo)
│ └── venv/ # Virtual environment (not in repo)
├── react-frontend/
│ ├── src/
│ │ ├── App.js # Main React component
│ │ └── index.js # Entry point for React
│ ├── package.json # Node dependencies for React
└── README.md # Project documentation
- Description: Accepts a URL, scrapes content, and returns generated questions.
- Request Body:
{ "url": "https://example.com" } - Response:
{ "questions": [ { "question": "What is your primary interest?", "options": ["Technology", "Science", "Literature"] } ] }
- Description: Accepts user responses and returns a category.
- Request Body:
{ "user_response": "Science, Hands-on Practice" } - Response:
{ "category": "You are a hands-on science enthusiast." }
For testing without consuming OpenAI API quota, mock the analyze_with_chatgpt function in app.py as follows:
def analyze_with_chatgpt(content):
return {
"questions": [
{
"question": "Sample question?",
"options": ["Option A", "Option B", "Option C"]
}
]
}This setup allows testing of the frontend without relying on the OpenAI API.
If you see a CORS error in the console, ensure flask-cors is installed, and CORS(app) is in your app.py file.
If you see "quota exceeded" errors, verify your OpenAI account plan and usage on the OpenAI Usage Page.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes and commit (
git commit -m 'Add feature'). - Push to the branch (
git push origin feature-branch). - Open a Pull Request.

