Spaces:
Sleeping
Sleeping
| 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() | |
| def assign_user_id(): | |
| if "user_id" not in session: | |
| session["user_id"] = str(uuid.uuid4()) | |
| 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) | |
| 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) |