Spaces:
Sleeping
Sleeping
File size: 1,313 Bytes
d1cad4b 6c6d1fa 4db208a 8c93fc6 8514dc9 4db208a 8514dc9 4db208a d1cad4b dbbf6b6 d1cad4b dbbf6b6 8c93fc6 d1cad4b dbbf6b6 d1cad4b 7678c37 8c93fc6 dbbf6b6 8c93fc6 4db208a d1cad4b dbbf6b6 6c6d1fa d1cad4b dbbf6b6 6c6d1fa |
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 |
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from fastapi.staticfiles import StaticFiles
from services.generate_questions_service import GenerateQuestionsService
from typing import Optional
# from data.load_data import retriever_pre
generate_questions_service = GenerateQuestionsService()
class Body(BaseModel):
school_subject: Optional[str] = None
subject: Optional[str] = None
difficultie: Optional[str] = None
promptValue: Optional[str] = None
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/generate_questions")
def generate_questions(body: Body):
if body.promptValue:
query = body.promptValue
else:
school_subject = body.school_subject
subject = body.subject
difficultie = body.difficultie
query = f"Quero que você gere questões de {school_subject}, sendo do assunto: {subject} e sendo da dificuldade: {difficultie}."
res = generate_questions_service.handle(f"""{query}""")
return res
app.mount("/", StaticFiles(directory="static", html=True), name="static")
if __name__ == "__main__":
import uvicorn
uvicorn.run("app:app", host="0.0.0.0", port=8000)
|