-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
70 lines (55 loc) · 1.62 KB
/
app.py
File metadata and controls
70 lines (55 loc) · 1.62 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
from flask import Flask, request, jsonify, render_template_string
app = Flask(__name__)
# Simple AI logic
def brain(text):
text = text.lower()
if "hello" in text:
return "Hello 👋 I am AstraQuant AI."
if "time" in text:
import datetime
return str(datetime.datetime.now())
return "I am still learning... 🤖"
# Home page (frontend inside Python)
@app.route("/")
def home():
return render_template_string("""
<!DOCTYPE html>
<html>
<head>
<title>AstraQuant Python AI</title>
<style>
body { background:black; color:#00ffcc; font-family:monospace; }
input { padding:10px; width:70%; }
button { padding:10px; }
</style>
</head>
<body>
<h2>🌑 AstraQuant Python AI</h2>
<div id="chat"></div>
<input id="msg" placeholder="Ask something..." />
<button onclick="send()">Send</button>
<script>
async function send() {
let msg = document.getElementById("msg").value;
let res = await fetch("/chat", {
method: "POST",
headers: {"Content-Type":"application/json"},
body: JSON.stringify({message: msg})
});
let data = await res.json();
document.getElementById("chat").innerHTML +=
"<p>You: " + msg + "</p>" +
"<p>AI: " + data.reply + "</p>";
}
</script>
</body>
</html>
""")
# API route
@app.route("/chat", methods=["POST"])
def chat():
user = request.json["message"]
reply = brain(user)
return jsonify({"reply": reply})
if __name__ == "__main__":
app.run(debug=True)