Spaces:
Running
Running
app.py
CHANGED
|
@@ -61,4 +61,64 @@ async def generate_content(client, model_name, system_instruction, borrador, is_
|
|
| 61 |
except Exception as e:
|
| 62 |
return f"Error en {model_name}: {str(e)}"
|
| 63 |
|
| 64 |
-
# Función predict para
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
except Exception as e:
|
| 62 |
return f"Error en {model_name}: {str(e)}"
|
| 63 |
|
| 64 |
+
# Función predict para procesar la entrada del usuario
|
| 65 |
+
async def predict(api_choice, borrador):
|
| 66 |
+
"""
|
| 67 |
+
api_choice: str - Define si se usará 'NVIDIA' o 'Google Gemini'.
|
| 68 |
+
borrador: str - El texto del borrador judicial que se debe procesar.
|
| 69 |
+
"""
|
| 70 |
+
system_instruction = default_system_instruction
|
| 71 |
+
model_name = "gemini-exp-1114" if api_choice == "Google Gemini" else "gpt-4"
|
| 72 |
+
|
| 73 |
+
# Verifica si se selecciona NVIDIA o Google Gemini
|
| 74 |
+
if api_choice == "NVIDIA":
|
| 75 |
+
client = nvidia_client
|
| 76 |
+
is_nvidia = True
|
| 77 |
+
elif api_choice == "Google Gemini":
|
| 78 |
+
client = google_model
|
| 79 |
+
is_nvidia = False
|
| 80 |
+
else:
|
| 81 |
+
return "Error: Debe seleccionar una API válida ('NVIDIA' o 'Google Gemini')."
|
| 82 |
+
|
| 83 |
+
# Llama a la función genérica de generación
|
| 84 |
+
result = await generate_content(client, model_name, system_instruction, borrador, is_nvidia)
|
| 85 |
+
return result
|
| 86 |
+
|
| 87 |
+
# Interfaz de usuario con Gradio
|
| 88 |
+
with gr.Blocks() as demo:
|
| 89 |
+
gr.Markdown("### Mejorador de Resoluciones Judiciales para Derecho de Familia - Chile")
|
| 90 |
+
|
| 91 |
+
# Selección de API (NVIDIA o Google Gemini)
|
| 92 |
+
api_choice = gr.Radio(
|
| 93 |
+
choices=["NVIDIA", "Google Gemini"],
|
| 94 |
+
label="Selecciona el modelo API",
|
| 95 |
+
value="Google Gemini"
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
# Campo de entrada para el borrador judicial
|
| 99 |
+
borrador = gr.Textbox(
|
| 100 |
+
label="Ingresa el borrador de la resolución judicial",
|
| 101 |
+
placeholder="Escribe o pega el texto aquí...",
|
| 102 |
+
lines=10
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
# Botón de procesamiento
|
| 106 |
+
submit_btn = gr.Button("Procesar texto")
|
| 107 |
+
|
| 108 |
+
# Campo de salida para el resultado procesado
|
| 109 |
+
output = gr.Textbox(
|
| 110 |
+
label="Resultado mejorado",
|
| 111 |
+
placeholder="El resultado aparecerá aquí...",
|
| 112 |
+
lines=10
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
# Conexión del botón con la función predict
|
| 116 |
+
submit_btn.click(
|
| 117 |
+
fn=lambda api_choice, borrador: asyncio.run(predict(api_choice, borrador)),
|
| 118 |
+
inputs=[api_choice, borrador],
|
| 119 |
+
outputs=output
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
# Iniciar el servidor Gradio
|
| 123 |
+
if __name__ == "__main__":
|
| 124 |
+
demo.launch()
|