Spaces:
Runtime error
Runtime error
import requests | |
import streamlit as st | |
import streamlit.components.v1 as components | |
import time | |
st.session_state.mytext = "" | |
global logtxt | |
global logtxtbox | |
logtxt = "" | |
def semanticComparativeClassification(): | |
st.session_state["respuesta"] = "" | |
apis_urls = [ | |
"https://api-inference.huggingface.co/models/symanto/sn-xlm-roberta-base-snli-mnli-anli-xnli", | |
"https://api-inference.huggingface.co/models/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2", | |
"https://api-inference.huggingface.co/models/sentence-transformers/distiluse-base-multilingual-cased-v2" | |
] | |
for api_url in apis_urls: | |
semanticComparativeClassificationCall(api_url) | |
def semanticComparativeClassificationCall(api_url: str): | |
st.write("Model: "+api_url+"\n") | |
time.sleep(1) | |
headers = {"Authorization": "Bearer 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"} | |
#API_URL = "https://api-inference.huggingface.co/models/Maite89/Roberta_finetuning_semantic_similarity_stsb_multi_mt" | |
def query(payload): | |
response = requests.post(api_url, headers=headers, json=payload) | |
return response.json() | |
sentences = [ | |
"Conoces Lya2 , que es Lya2", | |
"He perdido la contrase帽a, no puedo entrar o acceder a Lya2", | |
"Calendario de eventos, creamos un evento , borramos un evento ", | |
"Sincronizamos Lya2 con el tel茅fono o m贸bil" | |
"Cambios", | |
"Cambios dobles , pedir, autorizar , borrar un cambio doble", | |
"Cambios simples , pedir, autorizar , borrar un cambio simple", | |
"Sessiones", | |
"Personal", | |
"Horarios", | |
"脕reas", | |
"Rastryco o rastrico", | |
"Sylbo la aplicaci贸n m贸bil de Lya2", | |
"Sylbo", | |
"Hola hi hola", | |
"Adi贸s adi贸s bye", | |
"Como programo el personal", | |
"Como asigno trabajo al personal" | |
"Pedir permisos", | |
"Pedir vacaciones" | |
] | |
output = query({ | |
"inputs": { | |
"wait_for_model" : True, | |
"source_sentence": st.session_state.mytext, | |
"sentences": sentences | |
}, | |
}) | |
#st.write(output) | |
if "error" in output: | |
st.write(output["error"]) | |
else: | |
index=0 | |
for i in output: | |
st.write( str(i) +' - '+sentences[index]) | |
#container.write(i," - ", sentences[index]) | |
index = index + 1 | |
maxim = max(output) | |
sentenceindex = output.index(maxim) | |
if output[sentenceindex] < 0.3 : | |
st.write( "\nNo tengo respuesta para esto, 驴me lo explicas mejor o te pongo en contacto con un humano? ") | |
st.session_state["respuesta"]= st.session_state["respuesta"] +api_url+"\nNo tengo respuesta para esto, 驴me lo explicas mejor o te pongo en contacto con un humano?"+"\n\n" | |
else: | |
st.write("Tema reconocido: "+ str(sentences[sentenceindex])) | |
st.session_state["respuesta"] = st.session_state["respuesta"] +api_url+"\nTema reconocido: \n"+str(sentences[sentenceindex])+"\n\n" | |
#x = st.slider('Select a value') | |
#st.write(x, 'squared is', x * x) | |
st.session_state.response = "" | |
st.session_state.logresp = "" | |
st.title('Reconocimiento sem谩ntico') | |
title = st.text_input('Pregunta', '', on_change=semanticComparativeClassification,key='mytext') | |
st.text_area( "Respuesta: ", key= "respuesta", height=200 ) |