Marthee commited on
Commit
4c59dd2
·
verified ·
1 Parent(s): eb3c8a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -41,16 +41,18 @@ import Counting_Columns_2_1
41
  import Find_Hyperlinking_text
42
  import ezdxf
43
  from flask import Flask, render_template, session, redirect, url_for
44
-
45
  app = Flask(__name__)
46
 
47
- # Configure Flask-Session to store session data on the server (needed for Hugging Face Spaces)
48
- app.config["SESSION_TYPE"] = "filesystem" # Store sessions in temporary files
49
  app.config["SESSION_PERMANENT"] = False
50
- app.config["SESSION_FILE_DIR"] = "/tmp" # Use Hugging Face's temporary directory
51
  app.secret_key = "your_secret_key" # Replace with a secure key
52
 
53
- session(app) # Initialize Flask-Session
 
 
54
 
55
 
56
  prjnamesURL= 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=0'
@@ -70,30 +72,29 @@ def getInfotoMeasure():
70
  # Password Page Route
71
  @app.route("/password", methods=["GET", "POST"])
72
  def password_page():
73
- return render_template("gui2.html") # Render the password page (gui2.html)
74
 
75
  # Check Password Route
76
  @app.route("/check_password", methods=["POST"])
77
  def check_password():
78
- password = request.form.get("password") # Get password from form input
79
- correct_password = "c900" # Define the correct password
80
 
81
  if password == correct_password:
82
- session["authenticated"] = True # Store authentication status in session
83
- return jsonify({"authenticated": True}), 200 # Respond with success
84
  else:
85
- return jsonify({"authenticated": False}), 200 # Respond with failure
86
 
87
  # Main GUI Route (Checks Authentication)
88
  @app.route("/mainGUI", methods=["GET", "POST"])
89
  def main_gui():
90
- print("Session data:", session) # Debugging: print session contents
91
 
92
  if "authenticated" not in session or not session["authenticated"]:
93
- return redirect(url_for("gui2.html")) # Redirect if not authenticated
94
-
95
- return render_template("proposed-GUI.html") # Render the main GUI page
96
 
 
97
 
98
  @app.route("/WordSearch",methods=["GET", "POST"])
99
  def getInfo2toMeasure():
 
41
  import Find_Hyperlinking_text
42
  import ezdxf
43
  from flask import Flask, render_template, session, redirect, url_for
44
+ from flask_session import Session # Capital "S"
45
  app = Flask(__name__)
46
 
47
+ # Configure Flask-Session for server-side session storage
48
+ app.config["SESSION_TYPE"] = "filesystem"
49
  app.config["SESSION_PERMANENT"] = False
50
+ app.config["SESSION_FILE_DIR"] = "/tmp" # Hugging Face temporary storage
51
  app.secret_key = "your_secret_key" # Replace with a secure key
52
 
53
+ # Initialize Flask-Session (Fixed)
54
+ sess = Session()
55
+ sess.init_app(app)
56
 
57
 
58
  prjnamesURL= 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=0'
 
72
  # Password Page Route
73
  @app.route("/password", methods=["GET", "POST"])
74
  def password_page():
75
+ return render_template("gui2.html")
76
 
77
  # Check Password Route
78
  @app.route("/check_password", methods=["POST"])
79
  def check_password():
80
+ password = request.form.get("password")
81
+ correct_password = "c900"
82
 
83
  if password == correct_password:
84
+ session["authenticated"] = True # Store authentication in session
85
+ return jsonify({"authenticated": True}), 200
86
  else:
87
+ return jsonify({"authenticated": False}), 200
88
 
89
  # Main GUI Route (Checks Authentication)
90
  @app.route("/mainGUI", methods=["GET", "POST"])
91
  def main_gui():
92
+ print("Session data:", session) # Debugging: check session contents
93
 
94
  if "authenticated" not in session or not session["authenticated"]:
95
+ return redirect(url_for("gui2.html"))
 
 
96
 
97
+ return render_template("proposed-GUI.html")
98
 
99
  @app.route("/WordSearch",methods=["GET", "POST"])
100
  def getInfo2toMeasure():