Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from SBERT_Multilingue import buscar_marcas_similares as modelo_sbert
|
| 4 |
+
from BETO import buscar_marcas_similares as modelo_beto
|
| 5 |
+
|
| 6 |
+
def buscar_marcas(marca_input, umbral=80.0):
|
| 7 |
+
resultados = []
|
| 8 |
+
for modelo_func, nombre_modelo in [
|
| 9 |
+
(modelo_beto, "BETO"),
|
| 10 |
+
(modelo_sbert, "SBERT")
|
| 11 |
+
]:
|
| 12 |
+
try:
|
| 13 |
+
salida = modelo_func(marca_input)
|
| 14 |
+
for i, (marca, similitud) in enumerate(salida, start=1):
|
| 15 |
+
if similitud >= umbral:
|
| 16 |
+
resultados.append({
|
| 17 |
+
"Marca": marca.strip().lower(),
|
| 18 |
+
"Similitud (%)": round(similitud, 2),
|
| 19 |
+
"Modelo": nombre_modelo
|
| 20 |
+
})
|
| 21 |
+
except Exception as e:
|
| 22 |
+
print(f"Error en {nombre_modelo}: {e}")
|
| 23 |
+
|
| 24 |
+
if not resultados:
|
| 25 |
+
return []
|
| 26 |
+
|
| 27 |
+
df = pd.DataFrame(resultados)
|
| 28 |
+
df = df.sort_values("Similitud (%)", ascending=False)
|
| 29 |
+
df = df.drop_duplicates(subset="Marca", keep="first")
|
| 30 |
+
df["Marca"] = df["Marca"].str.title()
|
| 31 |
+
df = df.reset_index(drop=True)
|
| 32 |
+
df.index += 1
|
| 33 |
+
df.index.name = "Índice"
|
| 34 |
+
|
| 35 |
+
return df.reset_index().to_dict(orient="records")
|
| 36 |
+
|
| 37 |
+
iface = gr.Interface(
|
| 38 |
+
fn=buscar_marcas,
|
| 39 |
+
inputs=[
|
| 40 |
+
gr.Textbox(label="Marca a evaluar"),
|
| 41 |
+
gr.Slider(0, 100, value=80, label="Umbral mínimo de similitud (%)")
|
| 42 |
+
],
|
| 43 |
+
outputs="json",
|
| 44 |
+
examples=[["coca cola", 80], ["nike", 75]]
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
iface.launch()
|