How dhananjay-97/survey_generator works
Project Type & Purpose
• The project is a full-stack application centered around automating survey generation using AI. It features both a user-friendly web interface (via app.py) and a REST API interface (via flask_api.py) for programmatically generating surveys.
• The application leverages Flask, OpenAI’s GPT-3/ChatGPT APIs, and Python-docx for outputting survey documents in DOCX format.
Key Architectural Components
a. Web Interface Component:
• Web UI served by app.py.
• “templates” directory (HTML files) and the “static” assets (CSS from static/css), which together build the interactive survey creation wizard.
b. REST API Component:
• REST API endpoints provided by flask_api.py.
• Similarity in application logic between the web UI and API – both reach the core survey generation logic.
c. Survey Generation Module:
• Core logic (e.g., survey_generator.py) responsible for processing inputs (from either the UI or API) and delegating survey generation.
• This module uses stored “prompts” (see directories prompts/prompts_chatgpt and prompts/prompts_gpt3) that supply JSON templates for various survey questions.
d. External Services and Dependencies:
• OpenAI API: Show the external dependency where both the UI and API components call the AI (GPT-3/ChatGPT) for content creation.
• Configuration Source: Represent config.ini as the configuration file storing keys (e.g., OpenAI API keys).
Relationships & Data Flow
• The Survey Generation Module then fetches relevant “prompt” content (from the prompts directories), processes the request, and communicates with the OpenAI API.
• After processing, the module uses Python-docx to generate the DOCX file and returns the survey:
• For Web UI: The response is rendered using HTML templates.
• For REST API: The survey is returned as a downloadable file or a response payload.
Architectural Patterns & Design Principles
• Separation of concerns: Differentiate between presentation (templates and static files), application logic (Flask routes in app.py and flask_api.py), and core processing (survey_generator and prompt repositories).
• Modularity: Highlight the use of external prompt files for flexibility in survey generation and ease of maintenance.
• Configuration management: Emphasize how configuration settings (like the OpenAI API key stored in config.ini) are centrally managed.