Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,40 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
# 🔹
|
| 6 |
-
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
client = InferenceClient(
|
| 10 |
-
model="flax-community/spanish-t5-small",
|
| 11 |
-
api_key=API_KEY # Usa la API Key de Hugging Face
|
| 12 |
-
)
|
| 13 |
-
|
| 14 |
-
# 🔒 Clave secreta de acceso
|
| 15 |
SECRET_KEY = "MI_CLAVE_SUPER_SECRETA"
|
| 16 |
|
| 17 |
-
# 🔹 Función para
|
| 18 |
def reformular_texto(frase, clave):
|
| 19 |
if clave != SECRET_KEY:
|
| 20 |
return "🔴 Acceso denegado."
|
| 21 |
|
| 22 |
-
# 🔥
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
try:
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
-
return f"⚠ Error en la
|
| 30 |
|
| 31 |
# 🔹 Interfaz con Gradio
|
| 32 |
iface = gr.Interface(
|
|
@@ -34,8 +42,9 @@ iface = gr.Interface(
|
|
| 34 |
inputs=[gr.Textbox(label="Texto a reformular"), gr.Textbox(label="Clave de acceso", type="password")],
|
| 35 |
outputs="text",
|
| 36 |
title="Reformulador de Texto en Español",
|
| 37 |
-
description="
|
| 38 |
)
|
| 39 |
|
| 40 |
if __name__ == "__main__":
|
| 41 |
iface.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
|
|
|
| 3 |
|
| 4 |
+
# 🔹 Endpoint de la API de LanguageTool
|
| 5 |
+
API_URL = "https://api.languagetool.org/v2/check"
|
| 6 |
|
| 7 |
+
# 🔒 Clave secreta para la app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
SECRET_KEY = "MI_CLAVE_SUPER_SECRETA"
|
| 9 |
|
| 10 |
+
# 🔹 Función para corregir texto con LanguageTool
|
| 11 |
def reformular_texto(frase, clave):
|
| 12 |
if clave != SECRET_KEY:
|
| 13 |
return "🔴 Acceso denegado."
|
| 14 |
|
| 15 |
+
# 🔥 Llamada a LanguageTool para corrección gramatical
|
| 16 |
+
params = {
|
| 17 |
+
"text": frase,
|
| 18 |
+
"language": "es",
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
try:
|
| 22 |
+
response = requests.post(API_URL, data=params)
|
| 23 |
+
data = response.json()
|
| 24 |
+
|
| 25 |
+
# Extraemos la frase corregida
|
| 26 |
+
if "matches" in data and data["matches"]:
|
| 27 |
+
for match in data["matches"]:
|
| 28 |
+
if "replacements" in match and match["replacements"]:
|
| 29 |
+
replacement = match["replacements"][0]["value"]
|
| 30 |
+
offset = match["offset"]
|
| 31 |
+
length = match["length"]
|
| 32 |
+
frase = frase[:offset] + replacement + frase[offset+length:]
|
| 33 |
+
|
| 34 |
+
return frase
|
| 35 |
+
|
| 36 |
except Exception as e:
|
| 37 |
+
return f"⚠ Error en la corrección: {str(e)}"
|
| 38 |
|
| 39 |
# 🔹 Interfaz con Gradio
|
| 40 |
iface = gr.Interface(
|
|
|
|
| 42 |
inputs=[gr.Textbox(label="Texto a reformular"), gr.Textbox(label="Clave de acceso", type="password")],
|
| 43 |
outputs="text",
|
| 44 |
title="Reformulador de Texto en Español",
|
| 45 |
+
description="Usa LanguageTool para corregir y mejorar frases en español."
|
| 46 |
)
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|
| 49 |
iface.launch()
|
| 50 |
+
|