Spaces:
Sleeping
Sleeping
bego
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -5,17 +5,7 @@ import re
|
|
5 |
import torch
|
6 |
import numpy as np
|
7 |
from transformers import DistilBertTokenizer, DistilBertModel
|
8 |
-
from huggingface_hub import hf_hub_download
|
9 |
-
import os
|
10 |
-
|
11 |
-
# Obtener el token de Hugging Face desde la variable de entorno
|
12 |
-
hf_token = os.getenv("HF_TOKEN")
|
13 |
-
|
14 |
-
if hf_token is None:
|
15 |
-
raise ValueError("HF_TOKEN no est谩 configurado en las variables de entorno.")
|
16 |
-
|
17 |
-
# Iniciar sesi贸n en Hugging Face Hub
|
18 |
-
login(token=hf_token)
|
19 |
|
20 |
def corregir_codificacion(texto):
|
21 |
if isinstance(texto, str):
|
@@ -31,13 +21,13 @@ def preprocesar_texto(texto):
|
|
31 |
class ClasificadorOpiniones:
|
32 |
def __init__(self):
|
33 |
try:
|
34 |
-
model_path = hf_hub_download(repo_id="begoach1/opinion_classifier", filename="modelo_clasificador_reentrenado_lp_ros.pkl"
|
35 |
with open(model_path, 'rb') as f:
|
36 |
self.clf_combined = pickle.load(f)
|
37 |
except FileNotFoundError:
|
38 |
raise RuntimeError("El archivo del modelo no se encuentra.")
|
39 |
-
except pickle.UnpicklingError:
|
40 |
-
raise RuntimeError("Error al deserializar el modelo. Aseg煤rate de que el archivo no est茅 corrupto y que la versi贸n de scikit-learn sea compatible.")
|
41 |
except Exception as e:
|
42 |
raise RuntimeError(f"Error al descargar o cargar el modelo: {e}")
|
43 |
|
|
|
5 |
import torch
|
6 |
import numpy as np
|
7 |
from transformers import DistilBertTokenizer, DistilBertModel
|
8 |
+
from huggingface_hub import hf_hub_download
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def corregir_codificacion(texto):
|
11 |
if isinstance(texto, str):
|
|
|
21 |
class ClasificadorOpiniones:
|
22 |
def __init__(self):
|
23 |
try:
|
24 |
+
model_path = hf_hub_download(repo_id="begoach1/opinion_classifier", filename="modelo_clasificador_reentrenado_lp_ros.pkl")
|
25 |
with open(model_path, 'rb') as f:
|
26 |
self.clf_combined = pickle.load(f)
|
27 |
except FileNotFoundError:
|
28 |
raise RuntimeError("El archivo del modelo no se encuentra.")
|
29 |
+
except pickle.UnpicklingError as e:
|
30 |
+
raise RuntimeError(f"Error al deserializar el modelo. Aseg煤rate de que el archivo no est茅 corrupto y que la versi贸n de scikit-learn sea compatible. Detalles: {e}")
|
31 |
except Exception as e:
|
32 |
raise RuntimeError(f"Error al descargar o cargar el modelo: {e}")
|
33 |
|