Spaces:
Sleeping
Sleeping
lucas-wa
commited on
Commit
·
dbbf6b6
1
Parent(s):
71d17e3
Update interface
Browse files- server/app.py +10 -6
- web/src/App.jsx +98 -91
server/app.py
CHANGED
@@ -9,10 +9,11 @@ from typing import Optional
|
|
9 |
|
10 |
generate_questions_service = GenerateQuestionsService()
|
11 |
|
|
|
12 |
class Body(BaseModel):
|
13 |
-
|
14 |
-
subject: str
|
15 |
-
difficultie: str
|
16 |
promptValue: Optional[str] = None
|
17 |
|
18 |
|
@@ -25,21 +26,24 @@ app.add_middleware(
|
|
25 |
allow_headers=["*"],
|
26 |
)
|
27 |
|
|
|
28 |
@app.post("/generate_questions")
|
29 |
async def generate_questions(body: Body):
|
30 |
print(body)
|
31 |
-
matter = body.matter
|
32 |
-
subject = body.subject
|
33 |
-
difficultie = body.difficultie
|
34 |
if body.promptValue:
|
35 |
query = body.promptValue
|
36 |
else:
|
|
|
|
|
|
|
37 |
query = f"Quero que você gere questões de {school_subject}, sendo do assunto: {subject} e sendo da dificuldade: {difficultie}."
|
38 |
res = generate_questions_service.handle(f"""{query}""")
|
39 |
return res
|
40 |
|
|
|
41 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
import uvicorn
|
|
|
45 |
uvicorn.run("app:app", host="0.0.0.0", port=8000)
|
|
|
9 |
|
10 |
generate_questions_service = GenerateQuestionsService()
|
11 |
|
12 |
+
|
13 |
class Body(BaseModel):
|
14 |
+
school_subject: Optional[str] = None
|
15 |
+
subject: Optional[str] = None
|
16 |
+
difficultie: Optional[str] = None
|
17 |
promptValue: Optional[str] = None
|
18 |
|
19 |
|
|
|
26 |
allow_headers=["*"],
|
27 |
)
|
28 |
|
29 |
+
|
30 |
@app.post("/generate_questions")
|
31 |
async def generate_questions(body: Body):
|
32 |
print(body)
|
|
|
|
|
|
|
33 |
if body.promptValue:
|
34 |
query = body.promptValue
|
35 |
else:
|
36 |
+
school_subject = body.school_subject
|
37 |
+
subject = body.subject
|
38 |
+
difficultie = body.difficultie
|
39 |
query = f"Quero que você gere questões de {school_subject}, sendo do assunto: {subject} e sendo da dificuldade: {difficultie}."
|
40 |
res = generate_questions_service.handle(f"""{query}""")
|
41 |
return res
|
42 |
|
43 |
+
|
44 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
import uvicorn
|
48 |
+
|
49 |
uvicorn.run("app:app", host="0.0.0.0", port=8000)
|
web/src/App.jsx
CHANGED
@@ -46,20 +46,23 @@ function App() {
|
|
46 |
e.preventDefault();
|
47 |
setIsLoading(true);
|
48 |
try {
|
|
|
|
|
|
|
49 |
const res = await fetch("/generate_questions", {
|
50 |
method: "POST",
|
51 |
headers: {
|
52 |
"Content-Type": "application/json"
|
53 |
},
|
54 |
-
body: JSON.stringify(
|
55 |
-
subject, difficultie
|
56 |
-
})
|
57 |
});
|
|
|
58 |
console.log(res)
|
59 |
if (res.ok) {
|
60 |
const data = await res.json();
|
61 |
console.log(data)
|
62 |
-
setQuestions(data.questions);
|
|
|
63 |
} else {
|
64 |
toast.error("Erro ao gerar questões", {
|
65 |
position: "top-right",
|
@@ -112,95 +115,99 @@ function App() {
|
|
112 |
</header>
|
113 |
<main className="flex-1 flex overflow-hidden">
|
114 |
{menuState &&
|
115 |
-
|
116 |
-
<div className="
|
117 |
-
<
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
<form
|
123 |
-
onSubmit={handleSubmit}
|
124 |
-
className="flex flex-col gap-2.5 absolute top-0 bg-black/95 h-full md:h-fit z-10 md:static md:bg-transparent">
|
125 |
-
<div className="md:sr-only">
|
126 |
-
<ChevronLeft className="w-10 h-10" onClick={e => setMenuState(prev => !prev)} />
|
127 |
-
</div>
|
128 |
-
<fieldset>
|
129 |
-
<h2>Selecione uma matéria:</h2>
|
130 |
-
<Select defaultValue="biologia">
|
131 |
-
<SelectTrigger className="w-[180px]">
|
132 |
-
<SelectValue placeholder="Matéria" />
|
133 |
-
</SelectTrigger>
|
134 |
-
<SelectContent>
|
135 |
-
<SelectItem value="biologia">Biologia</SelectItem>
|
136 |
-
</SelectContent>
|
137 |
-
</Select>
|
138 |
-
<h2>Selecione um conteúdo:</h2>
|
139 |
-
<Select onValueChange={value => setSubject(value)}>
|
140 |
-
<SelectTrigger className="w-[180px]">
|
141 |
-
<SelectValue placeholder="Conteúdo" />
|
142 |
-
</SelectTrigger>
|
143 |
-
<SelectContent onChange={e => console.log(e)}>
|
144 |
-
{subjects && subjects.map(({ label, value }) => (
|
145 |
-
<SelectItem key={value} value={value}>{label}</SelectItem>
|
146 |
-
))}
|
147 |
-
</SelectContent>
|
148 |
-
</Select>
|
149 |
-
<h2>Selecione uma dificuldade:</h2>
|
150 |
-
<Select onValueChange={value => setDifficultie(value)}>
|
151 |
-
<SelectTrigger className="w-[180px]">
|
152 |
-
<SelectValue placeholder="Dificuldade" />
|
153 |
-
</SelectTrigger>
|
154 |
-
<SelectContent onChange={e => console.log(e)}>
|
155 |
-
{difficulties && difficulties.map(({ label, value }) => (
|
156 |
-
<SelectItem key={value} value={value}>{label}</SelectItem>
|
157 |
-
))}
|
158 |
-
</SelectContent>
|
159 |
-
</Select>
|
160 |
-
</fieldset>
|
161 |
-
<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"
|
162 |
-
disabled={isLoading || !subject || !difficultie}>
|
163 |
-
{isLoading ?
|
164 |
-
<div className="animate-spin h-5 w-5 border-2 border-white border-r-purple-500 rounded-full"></div>
|
165 |
-
:
|
166 |
-
"Enviar"
|
167 |
-
}
|
168 |
-
</button>
|
169 |
-
</form>
|
170 |
-
)}
|
171 |
-
|
172 |
-
|
173 |
</div>
|
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 |
<ToastContainer />
|
205 |
</main>
|
206 |
|
|
|
46 |
e.preventDefault();
|
47 |
setIsLoading(true);
|
48 |
try {
|
49 |
+
|
50 |
+
const body = promptMode ? { promptValue } : { subject, difficultie };
|
51 |
+
|
52 |
const res = await fetch("/generate_questions", {
|
53 |
method: "POST",
|
54 |
headers: {
|
55 |
"Content-Type": "application/json"
|
56 |
},
|
57 |
+
body: JSON.stringify(body)
|
|
|
|
|
58 |
});
|
59 |
+
|
60 |
console.log(res)
|
61 |
if (res.ok) {
|
62 |
const data = await res.json();
|
63 |
console.log(data)
|
64 |
+
setQuestions(data.rag_result.questions);
|
65 |
+
setPromptValue('');
|
66 |
} else {
|
67 |
toast.error("Erro ao gerar questões", {
|
68 |
position: "top-right",
|
|
|
115 |
</header>
|
116 |
<main className="flex-1 flex overflow-hidden">
|
117 |
{menuState &&
|
118 |
+
<div className="min-w-72 p-10 flex flex-col gap-5 absolute h-full top-0 bg-black/95 md:h-fit z-10 md:static md:bg-transparent">
|
119 |
+
<div className="md:sr-only">
|
120 |
+
<ChevronLeft className="w-10 h-10" onClick={e => setMenuState(prev => !prev)} />
|
121 |
+
</div>
|
122 |
+
<div className="flex items-center space-x-2">
|
123 |
+
<Switch id="prompt-mode" checked={promptMode} onCheckedChange={setPromptMode} />
|
124 |
+
<Label htmlFor="prompt-mode">Prompt Mode</Label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
</div>
|
126 |
+
{!promptMode && (
|
127 |
+
<form
|
128 |
+
onSubmit={handleSubmit}
|
129 |
+
className="flex flex-col gap-2.5 top-0 h-full ">
|
130 |
+
<fieldset>
|
131 |
+
<h2>Selecione uma matéria:</h2>
|
132 |
+
<Select defaultValue="biologia">
|
133 |
+
<SelectTrigger className="w-[180px]">
|
134 |
+
<SelectValue placeholder="Matéria" />
|
135 |
+
</SelectTrigger>
|
136 |
+
<SelectContent>
|
137 |
+
<SelectItem value="biologia">Biologia</SelectItem>
|
138 |
+
</SelectContent>
|
139 |
+
</Select>
|
140 |
+
<h2>Selecione um conteúdo:</h2>
|
141 |
+
<Select onValueChange={value => setSubject(value)}>
|
142 |
+
<SelectTrigger className="w-[180px]">
|
143 |
+
<SelectValue placeholder="Conteúdo" />
|
144 |
+
</SelectTrigger>
|
145 |
+
<SelectContent onChange={e => console.log(e)}>
|
146 |
+
{subjects && subjects.map(({ label, value }) => (
|
147 |
+
<SelectItem key={value} value={value}>{label}</SelectItem>
|
148 |
+
))}
|
149 |
+
</SelectContent>
|
150 |
+
</Select>
|
151 |
+
<h2>Selecione uma dificuldade:</h2>
|
152 |
+
<Select onValueChange={value => setDifficultie(value)}>
|
153 |
+
<SelectTrigger className="w-[180px]">
|
154 |
+
<SelectValue placeholder="Dificuldade" />
|
155 |
+
</SelectTrigger>
|
156 |
+
<SelectContent onChange={e => console.log(e)}>
|
157 |
+
{difficulties && difficulties.map(({ label, value }) => (
|
158 |
+
<SelectItem key={value} value={value}>{label}</SelectItem>
|
159 |
+
))}
|
160 |
+
</SelectContent>
|
161 |
+
</Select>
|
162 |
+
</fieldset>
|
163 |
+
<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"
|
164 |
+
disabled={isLoading || !subject || !difficultie}>
|
165 |
+
{isLoading ?
|
166 |
+
<div className="animate-spin h-5 w-5 border-2 border-white border-r-purple-500 rounded-full"></div>
|
167 |
+
:
|
168 |
+
"Enviar"
|
169 |
+
}
|
170 |
+
</button>
|
171 |
+
</form>
|
172 |
+
)}
|
173 |
+
</div>
|
174 |
}
|
175 |
+
<section className="p-10 flex-1 md:border-l-2 md:border-l-white flex flex-col gap-2.5 ">
|
176 |
+
{promptMode &&
|
177 |
+
<form
|
178 |
+
onSubmit={handleSubmit}>
|
179 |
+
<h2 className="text-2xl font-bold mb-5">Digite seu prompt para gerarmos as questões!</h2>
|
180 |
+
<Input placeholder="Digite seu prompt:" value={promptValue} onChange={(e) => setPromptValue(e.target.value)} />
|
181 |
+
<button className="h-10 w-full 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"
|
182 |
+
disabled={isLoading || !promptValue}>
|
183 |
+
{isLoading ?
|
184 |
+
<div className="animate-spin h-5 w-5 border-2 border-white border-r-purple-500 rounded-full"></div>
|
185 |
+
:
|
186 |
+
"Enviar"
|
187 |
+
}
|
188 |
+
</button>
|
189 |
+
</form>
|
190 |
+
}
|
191 |
+
<h2 className="text-2xl font-bold">Questões</h2>
|
192 |
+
<div className="w-full h-full flex flex-col gap-5 rounded p-2.5 overflow-y-scroll">
|
193 |
+
{questions ?
|
194 |
+
questions.map(({ question, options, answer }, index) => (
|
195 |
+
<div key={index} className="bg-slate-950 ring-2 ring-white p-2.5 rounded">
|
196 |
+
{question}<br /><br />
|
197 |
+
{options.map((option, i) => (
|
198 |
+
<div key={i}>
|
199 |
+
{option}
|
200 |
+
</div>
|
201 |
+
))}<br />
|
202 |
+
Resposta correta: {answer}
|
203 |
+
</div>
|
204 |
+
))
|
205 |
+
:
|
206 |
+
|
207 |
+
!promptMode && <div className="p-2.5 bg-slate-950 ring-2 ring-white rounded">Escolha os filtros para criar as questões</div>
|
208 |
+
}
|
209 |
+
</div>
|
210 |
+
</section>
|
211 |
<ToastContainer />
|
212 |
</main>
|
213 |
|