Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,6 +71,15 @@ try:
|
|
| 71 |
print(f"Tentando baixar pesos do repositório: {REPO_ID}...")
|
| 72 |
token = os.getenv("HF_TOKEN")
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
vortex_path = hf_hub_download(repo_id=REPO_ID, filename="vortex.pt", token=token)
|
| 75 |
emb_path = hf_hub_download(repo_id=REPO_ID, filename="embedding_projector.pt", token=token)
|
| 76 |
corr_path = hf_hub_download(repo_id=REPO_ID, filename="correction_projector.pt", token=token)
|
|
@@ -182,8 +191,15 @@ def predict(contexto, frase_mask, chaos_factor):
|
|
| 182 |
|
| 183 |
# Para cada palavra que aparece no contexto, aumentamos a probabilidade dela
|
| 184 |
for token_id in context_tokens:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
# O peso é proporcional ao Fator Caos.
|
| 186 |
-
# 0.5 é um ajuste fino para não ignorar totalmente a gramática.
|
| 187 |
resonance_bias[token_id] += (chaos_factor * 0.5)
|
| 188 |
|
| 189 |
# Injeta a ressonância nos logits originais
|
|
|
|
| 71 |
print(f"Tentando baixar pesos do repositório: {REPO_ID}...")
|
| 72 |
token = os.getenv("HF_TOKEN")
|
| 73 |
|
| 74 |
+
# Fallback para arquivo local (para quem não consegue criar ENV)
|
| 75 |
+
if not token and os.path.exists("token.txt"):
|
| 76 |
+
try:
|
| 77 |
+
with open("token.txt", "r") as f:
|
| 78 |
+
token = f.read().strip()
|
| 79 |
+
print("⚠️ Usando token do arquivo token.txt")
|
| 80 |
+
except:
|
| 81 |
+
pass
|
| 82 |
+
|
| 83 |
vortex_path = hf_hub_download(repo_id=REPO_ID, filename="vortex.pt", token=token)
|
| 84 |
emb_path = hf_hub_download(repo_id=REPO_ID, filename="embedding_projector.pt", token=token)
|
| 85 |
corr_path = hf_hub_download(repo_id=REPO_ID, filename="correction_projector.pt", token=token)
|
|
|
|
| 191 |
|
| 192 |
# Para cada palavra que aparece no contexto, aumentamos a probabilidade dela
|
| 193 |
for token_id in context_tokens:
|
| 194 |
+
# Verifica se é subword (começa com ##)
|
| 195 |
+
token_str = tokenizer.convert_ids_to_tokens(token_id)
|
| 196 |
+
|
| 197 |
+
# Pula subwords (ex: ##mos) e tokens especiais/curtos demais
|
| 198 |
+
# Isso evita que o modelo responda sufixos como "##mos"
|
| 199 |
+
if token_str.startswith("##") or len(token_str) < 2:
|
| 200 |
+
continue
|
| 201 |
+
|
| 202 |
# O peso é proporcional ao Fator Caos.
|
|
|
|
| 203 |
resonance_bias[token_id] += (chaos_factor * 0.5)
|
| 204 |
|
| 205 |
# Injeta a ressonância nos logits originais
|