Spaces:
Sleeping
Sleeping
app.py
CHANGED
@@ -58,29 +58,41 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
58 |
# Carga del modelo y el tokenizador
|
59 |
model_name = "mistralai/Mistral-Nemo-Instruct-2407"
|
60 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
|
61 |
model = AutoModelForCausalLM.from_pretrained(
|
62 |
model_name,
|
63 |
torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32,
|
64 |
device_map="auto" if device == "cuda" else None
|
65 |
)
|
66 |
|
67 |
-
@spaces.GPU(duration=120)
|
68 |
def mejorar_resolucion(input_text):
|
69 |
# Construcci贸n del prompt con instrucciones y entrada del usuario
|
70 |
-
prompt = f"
|
71 |
-
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
74 |
return response
|
75 |
|
76 |
-
#
|
77 |
-
|
78 |
-
|
79 |
-
gr.
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
|
85 |
# Lanzamiento de la aplicaci贸n
|
86 |
demo.launch()
|
|
|
58 |
# Carga del modelo y el tokenizador
|
59 |
model_name = "mistralai/Mistral-Nemo-Instruct-2407"
|
60 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
61 |
+
|
62 |
+
# Asegurar pad_token_id 煤nico
|
63 |
+
if tokenizer.pad_token_id is None or tokenizer.pad_token_id == tokenizer.eos_token_id:
|
64 |
+
tokenizer.pad_token_id = tokenizer.eos_token_id + 1
|
65 |
+
|
66 |
model = AutoModelForCausalLM.from_pretrained(
|
67 |
model_name,
|
68 |
torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32,
|
69 |
device_map="auto" if device == "cuda" else None
|
70 |
)
|
71 |
|
|
|
72 |
def mejorar_resolucion(input_text):
|
73 |
# Construcci贸n del prompt con instrucciones y entrada del usuario
|
74 |
+
prompt = f"{instrucciones}\n\n{input_text}"
|
75 |
+
inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True).to(device)
|
76 |
+
attention_mask = inputs['attention_mask']
|
77 |
+
outputs = model.generate(
|
78 |
+
inputs.input_ids,
|
79 |
+
attention_mask=attention_mask,
|
80 |
+
max_new_tokens=500,
|
81 |
+
temperature=0.3,
|
82 |
+
do_sample=True,
|
83 |
+
pad_token_id=tokenizer.pad_token_id
|
84 |
+
)
|
85 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
86 |
return response
|
87 |
|
88 |
+
# Configuraci贸n de la interfaz de Gradio
|
89 |
+
demo = gr.Interface(
|
90 |
+
fn=mejorar_resolucion,
|
91 |
+
inputs=gr.Textbox(label="Introduce tu resoluci贸n judicial"),
|
92 |
+
outputs=gr.Textbox(label="Resoluci贸n mejorada"),
|
93 |
+
title="Mejora de Resoluciones Judiciales con GPT Civil",
|
94 |
+
description="Utiliza el modelo Mistral-Nemo-Instruct-2407 para mejorar borradores de resoluciones judiciales."
|
95 |
+
)
|
96 |
|
97 |
# Lanzamiento de la aplicaci贸n
|
98 |
demo.launch()
|