Spaces:
Sleeping
Sleeping
File size: 7,589 Bytes
9bc6550 d1cad4b 9bc6550 6c6d1fa 9bc6550 5f10035 e8fbf6f 9bc6550 e8fbf6f 2ed6131 89bf64d e8fbf6f 6c6d1fa 9bc6550 d1cad4b 9bc6550 d1cad4b e8fbf6f 6c6d1fa d1cad4b 9bc6550 e8fbf6f d1cad4b 9bc6550 d1cad4b 9bc6550 d1cad4b 9bc6550 d1cad4b 9bc6550 d1cad4b 9bc6550 d1cad4b 9bc6550 d1cad4b 9bc6550 e8fbf6f 9bc6550 e8fbf6f 9bc6550 e8fbf6f 9bc6550 6c6d1fa 9bc6550 6c6d1fa 9bc6550 d1cad4b 9bc6550 d1cad4b 9bc6550 d1cad4b 9bc6550 d1cad4b 9bc6550 d1cad4b 9bc6550 |
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import { ChevronLeft, Menu } from "lucide-react"
import { useEffect, useState } from "react";
import { ToastContainer, toast } from "react-toastify"
import 'react-toastify/dist/ReactToastify.css';
function App() {
const [subject, setSubject] = useState("");
const [difficultie, setDifficultie] = useState("");
const [menuState, setMenuState] = useState(true);
const [isLoading, setIsLoading] = useState(false);
const [questions, setQuestions] = useState(null);
const [selectedMatter, setSelectedMatter] = useState("biologia");
const matter = [
{ label: "Biologia", value: "biologia" },
{ label: "História", value: "historia" },
];
const biologySubjects = [
{ label: "Fisiologia", value: "fisiologia" },
{ label: "Embriologia", value: "embriologia" },
{ label: "Citologia", value: "citologia" },
{ label: "Genética", value: "genetica" },
{ label: "Botânica", value: "botanica" },
{ label: "Zoologia", value: "zoologia" },
{ label: "Morfologia", value: "morfologia" },
{ label: "Ecologia", value: "ecologia" },
{ label: "Biofísica", value: "biofisica" },
]
const historySubjects = [
{ label: "Revoluções", value: "revoluções" },
{ label: "Grécia", value: "grécia" },
{ label: "Roma", value: "roma" },
{ label: "Primeira Guerra Mundial", value: "primeira guerra mundial" },
{ label: "Guerra Fria", value: "guerra fria" },
{ label: "Feudalismo", value: "feudalismo" },
]
const difficulties = [
{ label: "Fácil", value: "facil" },
{ label: "Intermediária", value: "intermediaria" },
{ label: "Difícil", value: "dificil" },
]
const handleSubmit = async (e) => {
e.preventDefault();
setIsLoading(true);
try {
const res = await fetch("/generate_questions", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
matter: selectedMatter,
subject, difficultie
})
});
if (res.ok) {
const data = await res.json();
setQuestions(data.rag_result.questions);
} else {
toast.error("Erro ao gerar questões", {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
className: "bg-slate-900 text-white font-semibold",
});
}
} catch (err) {
console.error(err);
toast.error("Erro ao gerar questões", {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
className: "bg-slate-900 text-white font-semibold",
});
}
setIsLoading(false);
}
useEffect(() => {
const handleResize = () => {
if (window.innerWidth > 768) {
setMenuState(true);
} else {
setMenuState(false);
}
}
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}
, []);
return (
<div className="font-sans h-screen text-white min-h-screen bg-slate-900 flex flex-col relative overflow-hidden">
<header className="p-10 flex items-center gap-2.5">
<Menu className="md:hidden" onClick={() => setMenuState(prev => !prev)} />
<h1 className="text-3xl font-bold">
Pergunt.<span className="text-transparent bg-clip-text bg-gradient-to-r from-green-300 to bg-blue-500">AÍ</span>
</h1>
</header>
<main className="flex-1 flex overflow-hidden">
{
menuState &&
<form
onSubmit={handleSubmit}
className="p-10 flex flex-col gap-2.5 absolute top-0 bg-black/95 h-full z-10 md:static md:h-full md:bg-transparent">
<div className="md:sr-only">
<ChevronLeft className="w-10 h-10" onClick={e => setMenuState(prev => !prev)} />
</div>
<h2>Selecione uma matéria:</h2>
<Select defaultValue="biologia" onValueChange={value => setSelectedMatter(value)}>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Matéria" />
</SelectTrigger>
<SelectContent >
{
matter.map(({ label, value }) => (
<SelectItem key={value} value={value}>{label}</SelectItem>
))
}
</SelectContent>
</Select>
<h2>Selecione um conteúdo:</h2>
<Select onValueChange={value => setSubject(value)}>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Conteúdo" />
</SelectTrigger>
<SelectContent onChange={e => console.log(e)}>
{
selectedMatter === "biologia" ?
biologySubjects.map(({ label, value }) => (
<SelectItem key={value} value={value}>{label}</SelectItem>
))
:
historySubjects.map(({ label, value }) => (
<SelectItem key={value} value={value}>{label}</SelectItem>
))
}
</SelectContent>
</Select>
<h2>Selecione uma dificuldade:</h2>
<Select onValueChange={value => setDifficultie(value)}>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Dificuldade" />
</SelectTrigger>
<SelectContent onChange={e => console.log(e)}>
{difficulties && difficulties.map(({ label, value }) => (
<SelectItem key={value} value={value}>{label}</SelectItem>
))}
</SelectContent>
</Select>
<button className="h-10 bg-purple-500 rounded px-2.5 py-1 mt-5 hover:brightness-110 transition-all flex items-center justify-center disabled:hover:brightness-75 disabled:brightness-75"
disabled={isLoading || !subject || !difficultie}>
{
isLoading ?
<div className="animate-spin h-5 w-5 border-2 border-white border-r-purple-500 rounded-full"></div>
:
"Enviar"
}
</button>
</form>
}
<section className="p-10 flex-1 md:border-l-2 md:border-l-white flex flex-col gap-2.5 ">
<h2 className="text-2xl font-bold">Questões</h2>
<div className="w-full h-full flex flex-col gap-5 rounded p-2.5 overflow-y-scroll">
{questions ?
questions.map(({ question, options, answer }, index) => (
<div key={index} className="bg-slate-950 ring-2 ring-white p-2.5 rounded">
{question}<br /><br />
{options.map((option, i) => (
<div key={i}>
{option}
</div>
))}<br />
Resposta correta: {answer}
</div>
))
: <div className="p-2.5 bg-slate-950 ring-2 ring-white rounded">{"Ainda sem questões"}</div>}
</div>
</section>
<ToastContainer />
</main>
</div>
)
}
export default App
|