from fastapi import FastAPI from transformers import pipeline import json app = FastAPI() medgemma = pipeline("text-generation", model="./fine_tuned_medgemma", tokenizer="./fine_tuned_medgemma") # Carregar JSON como base with open("questions.json", "r") as f: questions_base = json.load(f) @app.get("/generate") async def generate_question(theme: str, difficulty: str): prompt = f"Baseado nas questões da USP, gere uma questão de residência médica sobre {theme}, nível {difficulty}, com 4 opções (A, B, C, D) no estilo do JSON fornecido." response = medgemma(prompt, max_new_tokens=300, temperature=0.7, top_p=0.95)[0]['generated_text'] return {"question": response} @app.get("/simulado") async def get_simulado(num_questions: int = 5): simulado = [] for _ in range(num_questions): prompt = "Gere uma questão no estilo do JSON da USP sobre medicina, nível médio, com 4 opções." question = medgemma(prompt, max_new_tokens=300)[0]['generated_text'] simulado.append({"question": question, "options": ["A)", "B)", "C)", "D)"]}) # Placeholder return {"simulado": simulado}