from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from inference import rag_chain from pydantic import BaseModel from fastapi.staticfiles import StaticFiles class Body(BaseModel): subject: str app = FastAPI() app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"], ) @app.post("/generate_questions") async def generate_questions(body: Body): subject = body.subject query = f"Quero que vocĂȘ gere questĂ”es de biologia, sendo do assunto: {subject}." res = rag_chain.invoke(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)