|
import streamlit as st #line:1:import streamlit as st |
|
from bokeh .models .widgets import Button #line:2:from bokeh.models.widgets import Button |
|
from bokeh .models import CustomJS #line:3:from bokeh.models import CustomJS |
|
from streamlit_bokeh_events import streamlit_bokeh_events #line:4:from streamlit_bokeh_events import streamlit_bokeh_events |
|
import pandas as pd #line:6:import pandas as pd |
|
import numpy as np #line:7:import numpy as np |
|
from nltk .stem import SnowballStemmer #line:8:from nltk.stem import SnowballStemmer |
|
from inflector import Inflector ,English ,Spanish #line:9:from inflector import Inflector, English, Spanish |
|
inflector =Inflector (Spanish )#line:10:inflector = Inflector(Spanish) |
|
import unidecode #line:11:import unidecode |
|
import unicodedata #line:12:import unicodedata |
|
n =1 #line:13:n=1 |
|
p =0 #line:14:p=0 |
|
query="none" |
|
df =pd .read_excel ('preguntas_qh_tags2.xlsx',engine ="openpyxl")#line:15:df = pd.read_excel('preguntas_qh_tags2.xlsx',engine="openpyxl") |
|
def remove_accents (O0O00OO0O000OOO0O ):#line:17:def remove_accents(input_str): |
|
O000O0OO000000OOO =unicodedata .normalize ('NFKD',O0O00OO0O000OOO0O )#line:18:nfkd_form = unicodedata.normalize('NFKD', input_str) |
|
return u"".join ([O0O000O00O00O00OO for O0O000O00O00O00OO in O000O0OO000000OOO if not unicodedata .combining (O0O000O00O00O00OO )])#line:19:return u"".join([c for c in nfkd_form if not unicodedata.combining(c)]) |
|
stt_button =Button (label ="Speak")#line:25:stt_button = Button(label="Speak")#, width=100) |
|
stt_button .js_on_event ("button_click",CustomJS (code =""" |
|
var recognition = new webkitSpeechRecognition(); |
|
recognition.lang = "es-ES"; |
|
recognition.continuous = true; |
|
recognition.interimResults = true; |
|
|
|
recognition.onresult = function (e) { |
|
var value = ""; |
|
for (var i = e.resultIndex; i < e.results.length; ++i) { |
|
if (e.results[i].isFinal) { |
|
value += e.results[i][0].transcript; |
|
} |
|
} |
|
if ( value != "") { |
|
document.dispatchEvent(new CustomEvent("GET_TEXT", {detail: value})); |
|
} |
|
} |
|
recognition.start(); |
|
"""))#line:47:""")) |
|
result =streamlit_bokeh_events (stt_button ,events ="GET_TEXT",key ="listen",refresh_on_update =False ,override_height =75 ,debounce_time =0 )#line:56:debounce_time=0) |
|
placeholder =st .empty ()#line:59:placeholder = st.empty() |
|
placeholder .text ("Escuchando...")#line:62:placeholder.text("Escuchando...") |
|
if result :#line:66:if result: |
|
if "GET_TEXT"in result :#line:67:if "GET_TEXT" in result: |
|
placeholder .text ("Entendido!")#line:69:placeholder.text("Entendido!") |
|
st .text ("Entendido!")#line:70:st.text("Entendido!") |
|
placeholder .empty ()#line:72:placeholder.empty() |
|
#st .write (result .get ("GET_TEXT"))#line:74:st.write(result.get("GET_TEXT")) |
|
query =result .get ("GET_TEXT")#line:80:query=result.get("GET_TEXT") |
|
|
|
|
|
if query !="none":#line:86:if query!="salir": |
|
|
|
#st .text ("query: "+query )#line:81:st.text("query: "+query) |
|
query =query .lower ()#line:82:query = query.lower() |
|
if query !="salir":#line:87:if query!="none": |
|
#st .text ("query: "+query )#line:89:st.text("query: "+query) |
|
result =query .split ()#line:90:result=query.split() |
|
#st .text ("query: "+query )#line:91:st.text("query: "+query) |
|
df2 =[]#line:92:df2=[] |
|
for index ,row in df .iterrows ():#line:93:for index,row in df.iterrows(): |
|
list_words =df .loc [index ,'TAGS2']#line:96:list_words=df.loc[index,'TAGS2']#busca columna tag2 |
|
list_words =list_words .split (",")#line:97:list_words = list_words.split(",") |
|
df2 .append (list_words )#line:98:df2.append(list_words) |
|
ls5 =[]#line:103:ls5=[] |
|
list_words =[]#line:104:list_words=[] |
|
for indexw ,word in enumerate (result ):#line:105:for indexw, word in enumerate(result): |
|
result [indexw ]=inflector .singularize (str (word ))#line:106:result[indexw]=inflector.singularize(str(word)) |
|
#st .text ("result:"+str (result ))#line:107:st.text("result:" + str(result)) |
|
count_words =np .zeros (len (df .index ),dtype =int )#line:108:count_words = np.zeros(len(df.index), dtype=int) |
|
for index1 ,row in enumerate (df2 ):#line:109:for index1,row in enumerate(df2): |
|
ls4 =[]#line:112:ls4=[] |
|
for word in row :#line:123:for word in row : |
|
if word !=[]:#line:126:if word!=[]: |
|
for num in range (100 ):#line:128:for num in range (100): |
|
num =num /10 #line:130:num=num/10 |
|
num =str (num )#line:131:num=str(num) |
|
if word ==num :#line:133:if word==num: |
|
num =num .split (".")#line:135:num = num.split(".") |
|
ls4 .append (num [0 ])#line:137:ls4.append(num[0]) |
|
ls4 .append ("con")#line:139:ls4.append("con") |
|
ls4 .append (num [1 ])#line:140:ls4.append(num[1]) |
|
p =p +1 #line:141:p=p+1 |
|
if p ==0 :#line:143:if p==0: |
|
ls4 .append (word )#line:144:ls4.append(word) |
|
p =0 #line:145:p=0 |
|
ls5 .append (ls4 )#line:146:ls5.append(ls4) |
|
#if str (remove_accents (ls5 [index1 ][0 ]))==remove_accents (result [0 ]):#line:150:if str(remove_accents(ls5[index1][0]))==remove_accents(result[0]):# and ls[1]==first_word: |
|
if n==1: |
|
for resulted in result :#line:152:for resulted in result[1:]: |
|
for index2 ,word in enumerate (ls5 [index1 ]):#line:158:for index2,word in enumerate(ls5[index1][1:]) : |
|
if str (resulted )=="exactitec"or str (resulted )=="exactite"or str (resulted )=="exactec":#line:159:if str(resulted)=="h": |
|
resulted ="exactech" |
|
if str (resulted )=="h":#line:159:if str(resulted)=="h": |
|
resulted ="dh"#line:160:resulted="dh" |
|
if str (resulted )=="colón":#line:161:if str(resulted)=="colón": |
|
resulted ="coron"#line:162:resulted="coron" |
|
if str (resulted )=="trave"or str (resulted )=="travé":#line:163:if str(resulted)=="trave" or str(resulted)=="travé": |
|
resulted ="nope"#line:164:resulted="nope" |
|
if str (resulted )=="lasersolvo"or str (resulted )=="lásersolvo"or str (resulted )=="lásersolbo"or str (resulted )=="lasersolbo":#line:165:if str(resulted)=="lasersolvo"or str(resulted)=="lásersolvo"or str(resulted)=="lásersolbo"or str(resulted)=="lasersolbo": |
|
resulted ="solvo"#line:166:resulted="solvo" |
|
if str (resulted )=="solbo":#line:167:if str(resulted)=="solbo": |
|
resulted ="solvo"#line:168:resulted="solvo" |
|
if str (resulted )=="maya":#line:169:if str(resulted)=="maya": |
|
resulted ="malla"#line:170:resulted="malla" |
|
if str (resulted )=="pilos"or str (resulted )=="pilo":#line:171:if str(resulted)=="pilos"or str(resulted)=="pilo": |
|
resulted ="philo"#line:172:resulted="philo" |
|
if str (resulted )=="filos"or str (resulted )=="filo":#line:173:if str(resulted)=="filos"or str(resulted)=="filo": |
|
resulted ="philo"#line:174:resulted="philo" |
|
if str (resulted )=="sinces"or str (resulted )=="sinc":#line:175:if str(resulted)=="sinces" or str(resulted)=="sinc": |
|
resulted ="synthe"#line:176:resulted="synthe" |
|
if str (resulted )=="sintes"or str (resulted )=="sint":#line:177:if str(resulted)=="sintes" or str(resulted)=="sint": |
|
resulted ="synthe"#line:178:resulted="synthe" |
|
if str (resulted )=="axos"or str (resulted )=="axo":#line:179:if str(resulted)=="axos" or str(resulted)=="axo": |
|
resulted ="axso"#line:180:resulted="axso" |
|
if str (resulted )=="uno":#line:181:if str(resulted)=="uno": |
|
resulted ="1"#line:182:resulted="1" |
|
if str (resulted )=="dos"or str (resulted )=="do":#line:184:if str(resulted)=="dos" or str(resulted)=="do": |
|
resulted ="2"#line:185:resulted="2" |
|
if str (resulted )=="tres"or str (resulted )=="tr":#line:187:if str(resulted)=="tres" or str(resulted)=="tr": |
|
resulted ="3"#line:188:resulted="3" |
|
if str (resulted )=="cuatro"or str (resulted )=="cuatr":#line:190:if str(resulted)=="cuatro"or str(resulted)=="cuatr": |
|
resulted ="4"#line:191:resulted="4" |
|
if str (resulted )=="cinco"or str (resulted )=="cinc":#line:193:if str(resulted)=="cinco"or str(resulted)=="cinc": |
|
resulted ="5"#line:194:resulted="5" |
|
if str (resulted )=="seis"or str (resulted )=="sei":#line:196:if str(resulted)=="seis"or str(resulted)=="sei": |
|
resulted ="6"#line:197:resulted="6" |
|
if str (resulted )=="siete":#line:199:if str(resulted)=="siete": |
|
resulted ="7"#line:200:resulted="7" |
|
if str (resulted )=="ocho"or str (resulted )=="och":#line:202:if str(resulted)=="ocho"or str(resulted)=="och": |
|
resulted ="8"#line:203:resulted="8" |
|
if str (resulted )=="nueve"or str (resulted )=="nuev":#line:205:if str(resulted)=="nueve"or str(resulted)=="nuev": |
|
resulted ="9"#line:206:resulted="9" |
|
if str (resulted )=="cero":#line:208:if str(resulted)=="cero": |
|
resulted ="0"#line:209:resulted="0" |
|
if str(resulted)=="veintiuno": |
|
resulted="21" |
|
if str(resulted)=="veinte": |
|
resulted="20" |
|
if str(resulted)=="veintidos"or str(resulted)=="veintido" : |
|
resulted="22" |
|
if str(resulted)=="veintitres" or str(resulted)=="veintitre" : |
|
resulted="23" |
|
if str(resulted)=="veinticuatro": |
|
resulted="24" |
|
if str(resulted)=="veinticinco": |
|
resulted="25" |
|
if str(resulted)=="veintiseis"or str(resulted)=="veintisei" : |
|
resulted="26" |
|
if str(resulted)=="veintisiete": |
|
resulted="27" |
|
if str(resulted)=="veintiocho": |
|
resulted="28" |
|
if str(resulted)=="veintinueve": |
|
resulted="29" |
|
if str(resulted)=="treinta": |
|
resulted="30" |
|
|
|
if str (remove_accents (word )).lower ()==str (remove_accents (resulted )).lower ():#line:213:if str(remove_accents(word)).lower() == str(remove_accents(resulted)).lower(): |
|
count_words [index1 ]=count_words [index1 ]+1 #line:216:count_words[index1]=count_words[index1]+1 |
|
ls5 [index1 ].pop (index2 )#line:217:ls5[index1].pop(index2) |
|
indexmax =np .argwhere (count_words ==np .amax (count_words ))#line:219:indexmax = np.argwhere(count_words == np.amax(count_words)) |
|
all_zeros =not np .any (indexmax )#line:220:all_zeros = not np.any(indexmax) |
|
#st .text (count_words )#line:222:st.text(count_words) |
|
if not np .all (count_words ==0 ):#line:224:if not np.all(count_words==0): |
|
for indexin in indexmax :#line:226:for indexin in indexmax: |
|
|
|
#st .text (indexin )#line:228:st.text(indexin) |
|
#st .text (count_words [indexin ])#line:229:st.text(count_words[indexin]) |
|
|
|
st .text ("Si has preguntado...\n")#line:230:st.text("Si has preguntado...\n") |
|
st .text (df .iloc [indexin ,2])#line:231:st.text(df.iloc[indexin,2]) |
|
st .text ("La respuesta es...\n")#line:232:st.text("La respuesta es...\n") |
|
st .text (df .iloc [indexin ,3])#line:233:st.text(df.iloc[indexin,3]) |
|
print ("GRACIAS!") |