Spaces:
Running
Running
lucas-wa
commited on
Commit
·
e8fbf6f
1
Parent(s):
8514dc9
Adding history matter
Browse files- server/app.py +4 -10
- web/src/App.jsx +35 -9
server/app.py
CHANGED
@@ -4,17 +4,13 @@ from pydantic import BaseModel
|
|
4 |
from fastapi.staticfiles import StaticFiles
|
5 |
from services.generate_questions_service import GenerateQuestionsService
|
6 |
|
7 |
-
# from data.load_data import retriever_pre
|
8 |
-
|
9 |
generate_questions_service = GenerateQuestionsService()
|
10 |
|
11 |
-
|
12 |
class Body(BaseModel):
|
13 |
-
|
14 |
subject: str
|
15 |
difficultie: str
|
16 |
|
17 |
-
|
18 |
app = FastAPI()
|
19 |
|
20 |
app.add_middleware(
|
@@ -24,20 +20,18 @@ app.add_middleware(
|
|
24 |
allow_headers=["*"],
|
25 |
)
|
26 |
|
27 |
-
|
28 |
@app.post("/generate_questions")
|
29 |
async def generate_questions(body: Body):
|
30 |
-
|
|
|
31 |
subject = body.subject
|
32 |
difficultie = body.difficultie
|
33 |
-
query = f"Quero que você gere questões de {
|
34 |
res = generate_questions_service.handle(f"""{query}""")
|
35 |
return res
|
36 |
|
37 |
-
|
38 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
import uvicorn
|
42 |
-
|
43 |
uvicorn.run("app:app", host="0.0.0.0", port=8000)
|
|
|
4 |
from fastapi.staticfiles import StaticFiles
|
5 |
from services.generate_questions_service import GenerateQuestionsService
|
6 |
|
|
|
|
|
7 |
generate_questions_service = GenerateQuestionsService()
|
8 |
|
|
|
9 |
class Body(BaseModel):
|
10 |
+
matter: str
|
11 |
subject: str
|
12 |
difficultie: str
|
13 |
|
|
|
14 |
app = FastAPI()
|
15 |
|
16 |
app.add_middleware(
|
|
|
20 |
allow_headers=["*"],
|
21 |
)
|
22 |
|
|
|
23 |
@app.post("/generate_questions")
|
24 |
async def generate_questions(body: Body):
|
25 |
+
print(body)
|
26 |
+
matter = body.matter
|
27 |
subject = body.subject
|
28 |
difficultie = body.difficultie
|
29 |
+
query = f"Quero que você gere questões de {matter}, sendo do assunto: {subject} e sendo da dificuldade: {difficultie}."
|
30 |
res = generate_questions_service.handle(f"""{query}""")
|
31 |
return res
|
32 |
|
|
|
33 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
34 |
|
35 |
if __name__ == "__main__":
|
36 |
import uvicorn
|
|
|
37 |
uvicorn.run("app:app", host="0.0.0.0", port=8000)
|
web/src/App.jsx
CHANGED
@@ -18,8 +18,15 @@ function App() {
|
|
18 |
const [menuState, setMenuState] = useState(true);
|
19 |
const [isLoading, setIsLoading] = useState(false);
|
20 |
const [questions, setQuestions] = useState(null);
|
|
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
{ label: "Fisiologia", value: "fisiologia" },
|
24 |
{ label: "Embriologia", value: "embriologia" },
|
25 |
{ label: "Citologia", value: "citologia" },
|
@@ -31,6 +38,15 @@ function App() {
|
|
31 |
{ label: "Biofísica", value: "biofisica" },
|
32 |
]
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
const difficulties = [
|
35 |
{ label: "Fácil", value: "facil" },
|
36 |
{ label: "Intermediária", value: "intermediaria" },
|
@@ -46,14 +62,13 @@ function App() {
|
|
46 |
"Content-Type": "application/json"
|
47 |
},
|
48 |
body: JSON.stringify({
|
|
|
49 |
subject, difficultie
|
50 |
})
|
51 |
});
|
52 |
-
console.log(res)
|
53 |
if (res.ok) {
|
54 |
const data = await res.json();
|
55 |
-
|
56 |
-
setQuestions(data.questions);
|
57 |
} else {
|
58 |
toast.error("Erro ao gerar questões", {
|
59 |
position: "top-right",
|
@@ -114,12 +129,16 @@ function App() {
|
|
114 |
<ChevronLeft className="w-10 h-10" onClick={e => setMenuState(prev => !prev)} />
|
115 |
</div>
|
116 |
<h2>Selecione uma matéria:</h2>
|
117 |
-
<Select defaultValue="biologia" >
|
118 |
<SelectTrigger className="w-[180px]">
|
119 |
<SelectValue placeholder="Matéria" />
|
120 |
</SelectTrigger>
|
121 |
<SelectContent >
|
122 |
-
|
|
|
|
|
|
|
|
|
123 |
</SelectContent>
|
124 |
</Select>
|
125 |
<h2>Selecione um conteúdo:</h2>
|
@@ -128,9 +147,16 @@ function App() {
|
|
128 |
<SelectValue placeholder="Conteúdo" />
|
129 |
</SelectTrigger>
|
130 |
<SelectContent onChange={e => console.log(e)}>
|
131 |
-
{
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
</SelectContent>
|
135 |
</Select>
|
136 |
<h2>Selecione uma dificuldade:</h2>
|
|
|
18 |
const [menuState, setMenuState] = useState(true);
|
19 |
const [isLoading, setIsLoading] = useState(false);
|
20 |
const [questions, setQuestions] = useState(null);
|
21 |
+
const [selectedMatter, setSelectedMatter] = useState("biologia");
|
22 |
|
23 |
+
|
24 |
+
const matter = [
|
25 |
+
{ label: "Biologia", value: "biologia" },
|
26 |
+
{ label: "História", value: "historia" },
|
27 |
+
];
|
28 |
+
|
29 |
+
const biologySubjects = [
|
30 |
{ label: "Fisiologia", value: "fisiologia" },
|
31 |
{ label: "Embriologia", value: "embriologia" },
|
32 |
{ label: "Citologia", value: "citologia" },
|
|
|
38 |
{ label: "Biofísica", value: "biofisica" },
|
39 |
]
|
40 |
|
41 |
+
const historySubjects = [
|
42 |
+
{ label: "Revoluções", value: "revoluções" },
|
43 |
+
{ label: "Grécia", value: "grécia" },
|
44 |
+
{ label: "Roma", value: "roma" },
|
45 |
+
{ label: "Primeira Guerra Mundial", value: "primeira guerra mundial" },
|
46 |
+
{ label: "Guerra Fria", value: "guerra fria" },
|
47 |
+
{ label: "Feudalismo", value: "feudalismo" },
|
48 |
+
]
|
49 |
+
|
50 |
const difficulties = [
|
51 |
{ label: "Fácil", value: "facil" },
|
52 |
{ label: "Intermediária", value: "intermediaria" },
|
|
|
62 |
"Content-Type": "application/json"
|
63 |
},
|
64 |
body: JSON.stringify({
|
65 |
+
matter: selectedMatter,
|
66 |
subject, difficultie
|
67 |
})
|
68 |
});
|
|
|
69 |
if (res.ok) {
|
70 |
const data = await res.json();
|
71 |
+
setQuestions(data.rag_result.questions);
|
|
|
72 |
} else {
|
73 |
toast.error("Erro ao gerar questões", {
|
74 |
position: "top-right",
|
|
|
129 |
<ChevronLeft className="w-10 h-10" onClick={e => setMenuState(prev => !prev)} />
|
130 |
</div>
|
131 |
<h2>Selecione uma matéria:</h2>
|
132 |
+
<Select defaultValue="biologia" onValueChange={value => setSelectedMatter(value)}>
|
133 |
<SelectTrigger className="w-[180px]">
|
134 |
<SelectValue placeholder="Matéria" />
|
135 |
</SelectTrigger>
|
136 |
<SelectContent >
|
137 |
+
{
|
138 |
+
matter.map(({ label, value }) => (
|
139 |
+
<SelectItem key={value} value={value}>{label}</SelectItem>
|
140 |
+
))
|
141 |
+
}
|
142 |
</SelectContent>
|
143 |
</Select>
|
144 |
<h2>Selecione um conteúdo:</h2>
|
|
|
147 |
<SelectValue placeholder="Conteúdo" />
|
148 |
</SelectTrigger>
|
149 |
<SelectContent onChange={e => console.log(e)}>
|
150 |
+
{
|
151 |
+
selectedMatter === "biologia" ?
|
152 |
+
biologySubjects.map(({ label, value }) => (
|
153 |
+
<SelectItem key={value} value={value}>{label}</SelectItem>
|
154 |
+
))
|
155 |
+
:
|
156 |
+
historySubjects.map(({ label, value }) => (
|
157 |
+
<SelectItem key={value} value={value}>{label}</SelectItem>
|
158 |
+
))
|
159 |
+
}
|
160 |
</SelectContent>
|
161 |
</Select>
|
162 |
<h2>Selecione uma dificuldade:</h2>
|