- when opening VSCode, install the suggested extensions (Python, Black Formatter and Pylance)
- create your python environment
python3 -m venv .venv - copy the
.env.examplefile to a.envfile - replace the
OPENAI_API_KEYandOPENAI_ORGANIZATIONenv variables with the real values - activate your environment with
- download necessary data with
python -m nltk.downloader all - run the server with
flask --app main run --debug
The server should answer on http://localhost:5000
You can deactivate the environment with deactivate.
if you need to use a new librairies, you can do it with pip
pip install [library name] or pip3 install [library name]
Top-level layout:
main.py— Flask application and routesrequirements.txt— Python dependenciestemplates/— HTML templates (containsindex.html)static/— static files (JS/CSS)src/utils/— utility modules used by the appask_question_to_pdf.py— functions to ask questions to PDF/text and interface with GPTask_question_to_txt.py— (alternate) text-based helpertest_unitaire.py— small unit test scaffoldinghistoire.txt,test.txt— sample text files
The Flask app exposes the following endpoints (see main.py):
GET /- returns a small HTML/text ("Hello, World!")GET /hello/- renders theindex.htmltemplatePOST /prompt- expects a form fieldpromptand returns a JSON object{ 'answer': ... }fromask_question_to_pdfGET /question- returns a generated question viagpt3_question()POST /answer- expects a form fieldpromptand returns{ 'answer': ... }usinggpt3_answer
Example curl (POST to /prompt):
curl -X POST -F "prompt=Quel est le résumé ?" http://127.0.0.1:5000/prompt- The Flask app imports functions from
src/utils/ask_question_to_pdf.py. If you change those utilities, restart the Flask server to pick changes. - If you enable OpenAI features, make sure
OPENAI_API_KEYis set and valid. The project currently expects the key to be available via environment variables.
Install via pip and update requirements.txt:
pip install <package>
pip freeze > requirements.txt