Setting Up the Basic HTML Structure for the AI Short Story Generator

Introduction and Overview

Welcome to the first lesson of our course on building a Short Story Generation Web Application with Flask. In this lesson, we will focus on setting up the basic HTML structure for our application. This foundational step is crucial as it lays the groundwork for the entire web application. By the end of this lesson, you will have a well-structured HTML document that serves as the backbone for our AI Short Story Generator. Let's dive in and start building!

App File Structure

Before we start building the HTML for our story generation interface, let's take a moment to understand how our Flask application is organized. A clear file structure helps us stay organized as our project grows in complexity.

Here's the structure we'll be working with:

Shell
app/

├── main.py                     # Entry point for running the Flask app
├── requirements.txt            # Python dependencies

├── controllers/                # Flask route logic
│   └── story_generator_controller.py

├── services/                   # Core logic for story generation
│   └── story_generator_service.py

├── models/                     # Manages data and helper logic
│   ├── story_manager.py
│   └── prompt_manager.py

├── data/                       # Data template for story prompt
│   └── story_prompt_template.txt

├── static/                     # Frontend static files (CSS, JS, etc.)
│   ├── css/
│   │   └── style.css
│   └── script.js

├── templates/                  # HTML templates rendered by Flask
│   └── index.html

└── generated_stories/           # Directory to store generated stories

Folder Responsibilities

  • controllers/: Defines Flask routes and handles incoming requests.
  • services/: Contains the logic for formatting prompts and generating stories using AI.
  • models/: Deals with story storage and loading of prompt templates.
  • templates/ and static/: Support the front-end UI with HTML, CSS, and JavaScript.
  • data/: Holds reusable text templates to guide consistent story generation prompts.
  • generated_stories/: Where all generated stories are saved for viewing in the history tab.

With this structure in mind, you'll find it easier to understand where each part of the code lives as we build out the HTML and connect it to our Flask backend.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal