-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
69 lines (64 loc) · 2.39 KB
/
gui.py
File metadata and controls
69 lines (64 loc) · 2.39 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
// React + Tailwind web app for RaviBot
import React, { useState } from "react";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
import { ScrollArea } from "@/components/ui/scroll-area";
import { motion } from "framer-motion";
export default function RaviBotApp() {
const [messages, setMessages] = useState([
{ sender: "RaviBot", text: "Hi! Ask me anything about Grade 11 History." }
]);
const [query, setQuery] = useState("");
const [loading, setLoading] = useState(false);
const askRaviBot = async () => {
if (!query.trim()) return;
const userMessage = { sender: "You", text: query };
setMessages((prev) => [...prev, userMessage]);
setLoading(true);
setQuery("");
const response = await fetch("/api/ask", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query }),
});
const data = await response.json();
const botMessage = { sender: "RaviBot", text: data.answer };
setMessages((prev) => [...prev, botMessage]);
setLoading(false);
};
return (
<div className="min-h-screen bg-[#090a09] text-white p-4 flex flex-col">
<h1 className="text-3xl font-bold text-center text-[#798f0a] mb-4">RaviBot 🤖</h1>
<ScrollArea className="flex-1 overflow-y-auto space-y-3 mb-4 p-2">
{messages.map((msg, idx) => (
<motion.div
key={idx}
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3 }}
className={`w-fit max-w-[85%] px-4 py-2 rounded-2xl shadow ${
msg.sender === "RaviBot"
? "bg-[#1d1d1d] self-start"
: "bg-[#798f0a] text-black self-end"
}`}
>
<strong>{msg.sender}:</strong> {msg.text}
</motion.div>
))}
</ScrollArea>
<div className="flex gap-2">
<Input
value={query}
onChange={(e) => setQuery(e.target.value)}
onKeyDown={(e) => e.key === "Enter" && askRaviBot()}
className="bg-[#1d1d1d] border border-[#798f0a] text-white"
placeholder="Ask a history question..."
/>
<Button onClick={askRaviBot} disabled={loading}>
{loading ? "Thinking..." : "Send"}
</Button>
</div>
</div>
);
}