Spaces:
Build error
Build error
| from sentence_transformers import SentenceTransformer, util | |
| import gradio as gr | |
| import base64 | |
| model = SentenceTransformer('hiiamsid/sentence_similarity_spanish_es') | |
| def process_text(text1,text2,text3,text4): | |
| embeddings = model.encode([text1,text2,text3,text4],convert_to_tensor=True) | |
| score = util.cos_sim(embeddings,embeddings).numpy() | |
| return {text2 : score[0][1].item(),text3 : score[0][2].item(),text4 : score[0][3].item()} | |
| demo = gr.Blocks(title="Hola") | |
| def complete_with_gpt(text1,text2,text3): | |
| return text1+text2+text3 | |
| with open("Iso_Logotipo_Ceibal.png", "rb") as image_file: | |
| encoded_image = base64.b64encode(image_file.read()).decode() | |
| with demo: | |
| gr.Markdown( | |
| """ | |
| <center> | |
| <h1> | |
| Uso de AI para la comparación de frases y palabras. | |
| </h1> | |
| <img src='data:image/jpg;base64,{}' width=200px> | |
| <h3> | |
| Con este espacio podrás comparar la similitud entre distintas frases y palabras. El resultado es el porcentaje de similitud que el modelo encuentra entre la primer frase en comparación con las siguientes. | |
| </h3> | |
| </center> | |
| """.format(encoded_image)) | |
| with gr.Row(): | |
| with gr.Column(): | |
| with gr.Row(): | |
| gr.Markdown("Primero ingresá la primer frase:") | |
| with gr.Row(): | |
| text_input = gr.Textbox( label="") | |
| with gr.Row(): | |
| gr.Markdown("Ahora ingresá las frases a comparar con la primera:") | |
| with gr.Row(): | |
| text_input2 = gr.Textbox(label="Frase 1") | |
| with gr.Row(): | |
| text_input3 = gr.Textbox(label="Frase 2") | |
| with gr.Row(): | |
| text_input4 = gr.Textbox(label="Frase 3") | |
| with gr.Row(): | |
| btn = gr.Button("Calcular") | |
| with gr.Row(): | |
| examples = gr.Examples([["Hola, ¿Cómo estás?","Hola, ¿Todo bien?","Que feo está el día","Yo estoy bien"]],[text_input,text_input2, text_input3,text_input4]) | |
| with gr.Column(): | |
| with gr.Row(): | |
| text_output = gr.Label() | |
| btn.click(process_text, [text_input,text_input2, text_input3,text_input4], text_output) | |
| demo.launch() | |