File size: 11,795 Bytes
a6fea82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eaf8508
 
a6fea82
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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:
                    for resulted in result [1 :]:#line:152:for resulted in result[1:]:
                        for index2 ,word in enumerate (ls5 [index1 ][1 :]):#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 (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!")