-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
73 lines (56 loc) · 2.33 KB
/
app.py
File metadata and controls
73 lines (56 loc) · 2.33 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from flask import Flask, render_template, request, jsonify
from fpdf import FPDF
from docx import Document
import os
app = Flask(
__name__,
template_folder=os.path.join("Application", "templates"),
static_folder=os.path.join("Application", "static")
)
data_store = {
"linkedin": "",
"github": "",
"chat": []
}
@app.route('/')
def index():
return render_template('index.html')
@app.route('/submit_links', methods=['POST'])
def submit_links():
data_store["linkedin"] = request.form.get("linkedin")
data_store["github"] = request.form.get("github")
return jsonify({"message": "Links submitted successfully!"})
@app.route('/chat', methods=['POST'])
def chat():
user_message = request.json.get("message")
bot_response = f"You said: {user_message}. Tell me more!"
data_store["chat"].append({"user": user_message, "bot": bot_response})
return jsonify({"response": bot_response})
@app.route('/export', methods=['POST'])
def export():
export_type = request.form.get("export_type")
if export_type == "pdf":
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
pdf.cell(200, 10, txt="Chatbot Interaction Export", ln=True, align='C')
pdf.cell(200, 10, txt=f"LinkedIn: {data_store['linkedin']}", ln=True)
pdf.cell(200, 10, txt=f"GitHub: {data_store['github']}", ln=True)
for conversation in data_store["chat"]:
pdf.cell(200, 10, txt=f"User: {conversation['user']}", ln=True)
pdf.cell(200, 10, txt=f"Bot: {conversation['bot']}", ln=True)
pdf.output("chat_export.pdf")
return jsonify({"message": "Exported as PDF successfully!", "file": "chat_export.pdf"})
elif export_type == "word":
doc = Document()
doc.add_heading("Chatbot Interaction Export", level=1)
doc.add_paragraph(f"LinkedIn: {data_store['linkedin']}")
doc.add_paragraph(f"GitHub: {data_store['github']}")
for conversation in data_store["chat"]:
doc.add_paragraph(f"User: {conversation['user']}")
doc.add_paragraph(f"Bot: {conversation['bot']}")
doc.save("chat_export.docx")
return jsonify({"message": "Exported as Word successfully!", "file": "chat_export.docx"})
return jsonify({"message": "Invalid export type!"})
if __name__ == '__main__':
app.run(debug=True)