Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,11 @@ import streamlit as st
|
|
3 |
import streamlit.components.v1 as components
|
4 |
import time
|
5 |
|
|
|
6 |
st.session_state.mytext = ""
|
7 |
def semanticComparativeClassification():
|
8 |
st.session_state["respuesta"] = ""
|
|
|
9 |
apis_urls = [
|
10 |
"https://api-inference.huggingface.co/models/symanto/sn-xlm-roberta-base-snli-mnli-anli-xnli",
|
11 |
"https://api-inference.huggingface.co/models/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2",
|
@@ -16,12 +18,12 @@ def semanticComparativeClassification():
|
|
16 |
semanticComparativeClassificationCall(api_url)
|
17 |
|
18 |
def semanticComparativeClassificationCall(api_url: str):
|
19 |
-
|
20 |
-
st.
|
21 |
time.sleep(1)
|
22 |
headers = {"Authorization": "Bearer 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"}
|
23 |
#API_URL = "https://api-inference.huggingface.co/models/Maite89/Roberta_finetuning_semantic_similarity_stsb_multi_mt"
|
24 |
-
|
25 |
def query(payload):
|
26 |
response = requests.post(api_url, headers=headers, json=payload)
|
27 |
return response.json()
|
@@ -59,26 +61,24 @@ def semanticComparativeClassificationCall(api_url: str):
|
|
59 |
|
60 |
#st.write(output)
|
61 |
if "error" in output:
|
62 |
-
container.write(output["error"])
|
63 |
else:
|
64 |
index=0
|
65 |
for i in output:
|
66 |
-
|
|
|
67 |
index = index + 1
|
68 |
maxim = max(output)
|
69 |
-
|
70 |
-
|
71 |
|
72 |
-
sentenceindex = output.index(maxim)
|
73 |
-
|
74 |
-
container.write('Sentence index :', sentenceindex)
|
75 |
|
76 |
if output[sentenceindex] < 0.3 :
|
77 |
-
|
78 |
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"
|
79 |
else:
|
80 |
-
|
81 |
-
st.session_state["respuesta"]= st.session_state["respuesta"] +api_url+"\nTema reconocido: \n<span style='color:#f00'>"+str(sentences[sentenceindex])+"</span>\n\n"
|
82 |
|
83 |
|
84 |
|
@@ -92,8 +92,6 @@ st.title('Reconocimiento semántico')
|
|
92 |
title = st.text_input('Pregunta', '', on_change=semanticComparativeClassification,key='mytext')
|
93 |
|
94 |
st.text_area( "Respuesta: ", key= "respuesta", height=200 )
|
|
|
95 |
|
96 |
|
97 |
-
container = st.container()
|
98 |
-
container.write("This is inside the container")
|
99 |
-
|
|
|
3 |
import streamlit.components.v1 as components
|
4 |
import time
|
5 |
|
6 |
+
global container
|
7 |
st.session_state.mytext = ""
|
8 |
def semanticComparativeClassification():
|
9 |
st.session_state["respuesta"] = ""
|
10 |
+
st.session_state["log"] = ""
|
11 |
apis_urls = [
|
12 |
"https://api-inference.huggingface.co/models/symanto/sn-xlm-roberta-base-snli-mnli-anli-xnli",
|
13 |
"https://api-inference.huggingface.co/models/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2",
|
|
|
18 |
semanticComparativeClassificationCall(api_url)
|
19 |
|
20 |
def semanticComparativeClassificationCall(api_url: str):
|
21 |
+
|
22 |
+
st.session_state["log"] = st.session_state["log"] + "Model: ", api_url)+"\n"
|
23 |
time.sleep(1)
|
24 |
headers = {"Authorization": "Bearer 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"}
|
25 |
#API_URL = "https://api-inference.huggingface.co/models/Maite89/Roberta_finetuning_semantic_similarity_stsb_multi_mt"
|
26 |
+
|
27 |
def query(payload):
|
28 |
response = requests.post(api_url, headers=headers, json=payload)
|
29 |
return response.json()
|
|
|
61 |
|
62 |
#st.write(output)
|
63 |
if "error" in output:
|
64 |
+
st.session_state["log"] = st.session_state["log"] + container.write(output["error"])+'\n'
|
65 |
else:
|
66 |
index=0
|
67 |
for i in output:
|
68 |
+
st.session_state["log"] = st.session_state["log"]+i+' - '+sentences[index]+'\n'
|
69 |
+
#container.write(i," - ", sentences[index])
|
70 |
index = index + 1
|
71 |
maxim = max(output)
|
72 |
+
st.session_state["log"] = st.session_state["log"]+'MAX:', str(maxim),'\n')
|
|
|
73 |
|
74 |
+
sentenceindex = output.index(maxim)
|
|
|
|
|
75 |
|
76 |
if output[sentenceindex] < 0.3 :
|
77 |
+
st.session_state["log"] = st.session_state["log"]+api_url+"\nNo tengo respuesta para esto, ¿me lo explicas mejor o te pongo en contacto con un humano? \n\n"
|
78 |
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"
|
79 |
else:
|
80 |
+
st.session_state["log"] = st.session_state["log"]+api_url+"\nTema reconocido: ", str(sentences[sentenceindex])+"\n\n"
|
81 |
+
st.session_state["respuesta"] = st.session_state["respuesta"] +api_url+"\nTema reconocido: \n<span style='color:#f00'>"+str(sentences[sentenceindex])+"</span>\n\n"
|
82 |
|
83 |
|
84 |
|
|
|
92 |
title = st.text_input('Pregunta', '', on_change=semanticComparativeClassification,key='mytext')
|
93 |
|
94 |
st.text_area( "Respuesta: ", key= "respuesta", height=200 )
|
95 |
+
st.text_area( "Log: ", key= "log", height=600 )
|
96 |
|
97 |
|
|
|
|
|
|