forked from DarmorGamz/Youtube-Shorts-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
67 lines (53 loc) · 1.85 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# coding: utf-8
"""
This module initializes a Flask web application for managing and rendering templates
for an interactive GUI. It includes routes for the main index page and settings page,
and sets headers to disable caching for all responses. The application can be launched
locally, opening the default web browser to the specified port.
Modules Imported:
- webbrowser: Standard library for opening URLs in a web browser.
- Path: Pathlib module for filesystem path operations.
- tomlkit: TOML parser and writer for handling configuration files.
- Flask, render_template, request: Flask web framework for creating web applications.
Routes:
- /: Renders the main index page.
- /settings: Renders the settings page.
Usage:
Run this module directly to start the Flask web application on the specified port.
"""
import webbrowser
from flask import Flask, render_template
app = Flask(__name__, template_folder="gui")
@app.after_request
def after_request(response):
"""
Modifies response headers to prevent caching.
Args:
response (Response): The Flask response object.
Returns:
Response: The modified response object with no-cache headers.
"""
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Expires"] = 0
response.headers["Pragma"] = "no-cache"
return response
@app.route("/")
def index():
"""
Renders the main index page.
Returns:
str: The rendered HTML of the index page.
"""
return render_template("index.html")
@app.route("/settings", methods=["GET", "POST"])
def settings():
"""
Renders the settings page.
Returns:
str: The rendered HTML of the settings page.
"""
return render_template("settings.html")
PORT = 4000
if __name__ == "__main__":
webbrowser.open(f"http://localhost:{PORT}", new=2)
app.run(port=PORT)