forked from Rishi098/Basic-Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAiNotesApp.py
More file actions
57 lines (50 loc) · 1.71 KB
/
Copy pathAiNotesApp.py
File metadata and controls
57 lines (50 loc) · 1.71 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from flask import Flask, request, render_template_string
from transformers import pipeline
app = Flask(__name__)
# Initialize the summarization model
summarizer = pipeline("summarization")
notes = []
# HTML template for the notes app
template = """
<!doctype html>
<html>
<head><title>AI Notes App</title></head>
<body>
<h1>AI Notes App</h1>
<form method="post">
<textarea name="note" rows="4" cols="50" placeholder="Enter your note here..."></textarea><br>
<button type="submit">Add Note</button>
</form>
<h2>Notes</h2>
<ul>
{% for note in notes %}
<li>{{ note }}</li>
{% endfor %}
</ul>
<h2>Summarized Note</h2>
<form method="post" action="/summarize">
<textarea name="summary_note" rows="4" cols="50" placeholder="Enter note to summarize..."></textarea><br>
<button type="submit">Summarize Note</button>
</form>
{% if summary %}
<p>Summary: {{ summary }}</p>
{% endif %}
</body>
</html>
"""
@app.route("/", methods=["GET", "POST"])
def home():
if request.method == "POST":
note = request.form["note"]
if note:
notes.append(note)
return render_template_string(template, notes=notes, summary=None)
@app.route("/summarize", methods=["POST"])
def summarize():
summary_note = request.form["summary_note"]
if summary_note:
summary = summarizer(summary_note, max_length=50, min_length=25, do_sample=False)[0]['summary_text']
return render_template_string(template, notes=notes, summary=summary)
return render_template_string(template, notes=notes, summary=None)
if __name__ == "__main__":
app.run(debug=True)