-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
42 lines (33 loc) · 1.3 KB
/
Copy pathapp.py
File metadata and controls
42 lines (33 loc) · 1.3 KB
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
import uuid
from flask import Flask, render_template, request, session
from db import init_db, save_history, get_user_history, enforce_history_limit
from utils import summarize_text, extract_tags, detect_sentiment
app = Flask(__name__)
app.secret_key = "dev-secret" # creates an ID for session cookies
init_db()
@app.before_request
def assign_user_id():
if "user_id" not in session:
session["user_id"] = str(uuid.uuid4())
@app.route("/", methods=["GET", "POST"])
def index():
summary = tags = sentiment = None
if request.method == "POST":
text = request.form["text"].strip()
if not text:
return render_template("index.html", error="Please enter some text.")
user_id = session["user_id"]
enforce_history_limit(user_id)
summary = summarize_text(text)
tags = extract_tags(text)
sentiment = detect_sentiment(text)
save_history(user_id, text, summary, tags, sentiment)
print(session)
return render_template("index.html", summary=summary, tags=tags, sentiment=sentiment)
@app.route("/history")
def history():
user_id = session.get("user_id")
notes = get_user_history(user_id)
return render_template("history.html", notes=notes)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860, debug=False)