Update app2.py
Browse files
app2.py
CHANGED
|
@@ -8,7 +8,7 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
| 8 |
# CONFIGURAÇÕES DO MODELO LOCAL
|
| 9 |
# -------------------------------------
|
| 10 |
MODEL_NAME = "Qwen/Qwen2.5-0.5B-Instruct"
|
| 11 |
-
DATASET_REPO = "caarleexx/
|
| 12 |
LOCAL_DATA_FILE = "data.json"
|
| 13 |
|
| 14 |
print("[LOG] Carregando modelo...")
|
|
@@ -29,7 +29,7 @@ generator = pipeline(
|
|
| 29 |
# FUNÇÃO: gerar pergunta + N opções
|
| 30 |
# -------------------------------------
|
| 31 |
def gerar_pergunta_e_opcoes():
|
| 32 |
-
N = random.randint(
|
| 33 |
prompt = (
|
| 34 |
f"Crie uma pergunta curta. "
|
| 35 |
f"A pergunta deve ter exatamente {N} respostas possíveis, todas bem diferentes entre si."
|
|
@@ -45,7 +45,7 @@ def gerar_pergunta_e_opcoes():
|
|
| 45 |
# -------------------------------------
|
| 46 |
def gerar_resposta(pergunta):
|
| 47 |
print(f"[LOG] Gerando resposta principal...")
|
| 48 |
-
resp = generator(f"
|
| 49 |
return resp
|
| 50 |
|
| 51 |
# -------------------------------------
|
|
@@ -53,9 +53,9 @@ def gerar_resposta(pergunta):
|
|
| 53 |
# -------------------------------------
|
| 54 |
def gerar_alternativas(pergunta, N):
|
| 55 |
prompt = (
|
| 56 |
-
f"
|
| 57 |
f"Liste {N} respostas possíveis, todas diferentes entre si, "
|
| 58 |
-
f"sem justificativas. Apenas a lista."
|
| 59 |
)
|
| 60 |
|
| 61 |
print(f"[LOG] Gerando {N} alternativas divergentes...")
|
|
@@ -90,7 +90,7 @@ def divergencia(resposta_principal, alternativas):
|
|
| 90 |
def gerar_explicacao(pergunta):
|
| 91 |
prompt = (
|
| 92 |
f"Explique, de forma detalhada, por que a pergunta abaixo pode gerar respostas tão diferentes:\n"
|
| 93 |
-
f"{pergunta}"
|
| 94 |
)
|
| 95 |
|
| 96 |
print("[LOG] Gerando explicação...")
|
|
@@ -133,11 +133,11 @@ def loop_geracao(qtd=10):
|
|
| 133 |
explicacao = gerar_explicacao(pergunta)
|
| 134 |
|
| 135 |
novo_registro = {
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
}
|
| 142 |
|
| 143 |
print("[LOG] Adicionando exemplo ao dataset...")
|
|
|
|
| 8 |
# CONFIGURAÇÕES DO MODELO LOCAL
|
| 9 |
# -------------------------------------
|
| 10 |
MODEL_NAME = "Qwen/Qwen2.5-0.5B-Instruct"
|
| 11 |
+
DATASET_REPO = "caarleexx/AM1"
|
| 12 |
LOCAL_DATA_FILE = "data.json"
|
| 13 |
|
| 14 |
print("[LOG] Carregando modelo...")
|
|
|
|
| 29 |
# FUNÇÃO: gerar pergunta + N opções
|
| 30 |
# -------------------------------------
|
| 31 |
def gerar_pergunta_e_opcoes():
|
| 32 |
+
N = random.randint(1, 3) # número aleatório de alternativas
|
| 33 |
prompt = (
|
| 34 |
f"Crie uma pergunta curta. "
|
| 35 |
f"A pergunta deve ter exatamente {N} respostas possíveis, todas bem diferentes entre si."
|
|
|
|
| 45 |
# -------------------------------------
|
| 46 |
def gerar_resposta(pergunta):
|
| 47 |
print(f"[LOG] Gerando resposta principal...")
|
| 48 |
+
resp = generator(f"{pergunta}\nResponda de forma curta e direta.")[0]["generated_text"]
|
| 49 |
return resp
|
| 50 |
|
| 51 |
# -------------------------------------
|
|
|
|
| 53 |
# -------------------------------------
|
| 54 |
def gerar_alternativas(pergunta, N):
|
| 55 |
prompt = (
|
| 56 |
+
f"{pergunta}\n"
|
| 57 |
f"Liste {N} respostas possíveis, todas diferentes entre si, "
|
| 58 |
+
f"sem justificativas. a rssposta deve conter Apenas a lista."
|
| 59 |
)
|
| 60 |
|
| 61 |
print(f"[LOG] Gerando {N} alternativas divergentes...")
|
|
|
|
| 90 |
def gerar_explicacao(pergunta):
|
| 91 |
prompt = (
|
| 92 |
f"Explique, de forma detalhada, por que a pergunta abaixo pode gerar respostas tão diferentes:\n"
|
| 93 |
+
f"{pergunta} a sus respista deve ser clara para detalhsr conexao das a rsposra sem explicação ou justificativa"
|
| 94 |
)
|
| 95 |
|
| 96 |
print("[LOG] Gerando explicação...")
|
|
|
|
| 133 |
explicacao = gerar_explicacao(pergunta)
|
| 134 |
|
| 135 |
novo_registro = {
|
| 136 |
+
pergunta,
|
| 137 |
+
resposta,
|
| 138 |
+
alternativas,
|
| 139 |
+
divergencias,
|
| 140 |
+
explicacao
|
| 141 |
}
|
| 142 |
|
| 143 |
print("[LOG] Adicionando exemplo ao dataset...")
|