mariavhrh commited on
Commit
aec712c
1 Parent(s): 3cc762d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +142 -0
app.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st #line:1:import streamlit as st
2
+ from bokeh .models .widgets import Button #line:2:from bokeh.models.widgets import Button
3
+ from bokeh .models import CustomJS #line:3:from bokeh.models import CustomJS
4
+ from streamlit_bokeh_events import streamlit_bokeh_events #line:4:from streamlit_bokeh_events import streamlit_bokeh_events
5
+ import pandas as pd #line:6:import pandas as pd
6
+ import numpy as np #line:7:import numpy as np
7
+ from nltk .stem import SnowballStemmer #line:8:from nltk.stem import SnowballStemmer
8
+ from inflector import Inflector ,English ,Spanish #line:9:from inflector import Inflector, English, Spanish
9
+ inflector =Inflector (Spanish )#line:10:inflector = Inflector(Spanish)
10
+ import unidecode #line:11:import unidecode
11
+ import unicodedata #line:12:import unicodedata
12
+ n =1 #line:13:n=1
13
+ p =0 #line:14:p=0
14
+ df =pd .read_excel ('preguntas_qh_tags2.xlsx',engine ="openpyxl")#line:15:df = pd.read_excel('preguntas_qh_tags2.xlsx',engine="openpyxl")
15
+ def remove_accents (O0O00OO0O000OOO0O ):#line:17:def remove_accents(input_str):
16
+ O000O0OO000000OOO =unicodedata .normalize ('NFKD',O0O00OO0O000OOO0O )#line:18:nfkd_form = unicodedata.normalize('NFKD', input_str)
17
+ 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)])
18
+ stt_button =Button (label ="Speak")#line:25:stt_button = Button(label="Speak")#, width=100)
19
+ stt_button .js_on_event ("button_click",CustomJS (code ="""
20
+ var recognition = new webkitSpeechRecognition();
21
+ recognition.lang = "es-ES";
22
+ recognition.continuous = true;
23
+ recognition.interimResults = true;
24
+
25
+ recognition.onresult = function (e) {
26
+ var value = "";
27
+ for (var i = e.resultIndex; i < e.results.length; ++i) {
28
+ if (e.results[i].isFinal) {
29
+ value += e.results[i][0].transcript;
30
+ }
31
+ }
32
+ if ( value != "") {
33
+ document.dispatchEvent(new CustomEvent("GET_TEXT", {detail: value}));
34
+ }
35
+ }
36
+ recognition.start();
37
+ """))#line:47:"""))
38
+ 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)
39
+ placeholder =st .empty ()#line:59:placeholder = st.empty()
40
+ placeholder .text ("Escuchando...")#line:62:placeholder.text("Escuchando...")
41
+ if result :#line:66:if result:
42
+ if "GET_TEXT"in result :#line:67:if "GET_TEXT" in result:
43
+ placeholder .text ("Entendido!")#line:69:placeholder.text("Entendido!")
44
+ st .text ("Entendido!")#line:70:st.text("Entendido!")
45
+ placeholder .empty ()#line:72:placeholder.empty()
46
+ st .write (result .get ("GET_TEXT"))#line:74:st.write(result.get("GET_TEXT"))
47
+ query =result .get ("GET_TEXT")#line:80:query=result.get("GET_TEXT")
48
+ st .text ("query: "+query )#line:81:st.text("query: "+query)
49
+ query =query .lower ()#line:82:query = query.lower()
50
+ if query !="salir":#line:86:if query!="salir":
51
+ if query !="none":#line:87:if query!="none":
52
+ st .text ("query: "+query )#line:89:st.text("query: "+query)
53
+ result =query .split ()#line:90:result=query.split()
54
+ st .text ("query: "+query )#line:91:st.text("query: "+query)
55
+ df2 =[]#line:92:df2=[]
56
+ for index ,row in df .iterrows ():#line:93:for index,row in df.iterrows():
57
+ list_words =df .loc [index ,'TAGS2']#line:96:list_words=df.loc[index,'TAGS2']#busca columna tag2
58
+ list_words =list_words .split (",")#line:97:list_words = list_words.split(",")
59
+ df2 .append (list_words )#line:98:df2.append(list_words)
60
+ ls5 =[]#line:103:ls5=[]
61
+ list_words =[]#line:104:list_words=[]
62
+ for indexw ,word in enumerate (result ):#line:105:for indexw, word in enumerate(result):
63
+ result [indexw ]=inflector .singularize (str (word ))#line:106:result[indexw]=inflector.singularize(str(word))
64
+ st .text ("result:"+str (result ))#line:107:st.text("result:" + str(result))
65
+ count_words =np .zeros (len (df .index ),dtype =int )#line:108:count_words = np.zeros(len(df.index), dtype=int)
66
+ for index1 ,row in enumerate (df2 ):#line:109:for index1,row in enumerate(df2):
67
+ ls4 =[]#line:112:ls4=[]
68
+ for word in row :#line:123:for word in row :
69
+ if word !=[]:#line:126:if word!=[]:
70
+ for num in range (100 ):#line:128:for num in range (100):
71
+ num =num /10 #line:130:num=num/10
72
+ num =str (num )#line:131:num=str(num)
73
+ if word ==num :#line:133:if word==num:
74
+ num =num .split (".")#line:135:num = num.split(".")
75
+ ls4 .append (num [0 ])#line:137:ls4.append(num[0])
76
+ ls4 .append ("con")#line:139:ls4.append("con")
77
+ ls4 .append (num [1 ])#line:140:ls4.append(num[1])
78
+ p =p +1 #line:141:p=p+1
79
+ if p ==0 :#line:143:if p==0:
80
+ ls4 .append (word )#line:144:ls4.append(word)
81
+ p =0 #line:145:p=0
82
+ ls5 .append (ls4 )#line:146:ls5.append(ls4)
83
+ 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:
84
+ for resulted in result [1 :]:#line:152:for resulted in result[1:]:
85
+ for index2 ,word in enumerate (ls5 [index1 ][1 :]):#line:158:for index2,word in enumerate(ls5[index1][1:]) :
86
+ if str (resulted )=="h":#line:159:if str(resulted)=="h":
87
+ resulted ="dh"#line:160:resulted="dh"
88
+ if str (resulted )=="colón":#line:161:if str(resulted)=="colón":
89
+ resulted ="coron"#line:162:resulted="coron"
90
+ if str (resulted )=="trave"or str (resulted )=="travé":#line:163:if str(resulted)=="trave" or str(resulted)=="travé":
91
+ resulted ="nope"#line:164:resulted="nope"
92
+ 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":
93
+ resulted ="solvo"#line:166:resulted="solvo"
94
+ if str (resulted )=="solbo":#line:167:if str(resulted)=="solbo":
95
+ resulted ="solvo"#line:168:resulted="solvo"
96
+ if str (resulted )=="maya":#line:169:if str(resulted)=="maya":
97
+ resulted ="malla"#line:170:resulted="malla"
98
+ if str (resulted )=="pilos"or str (resulted )=="pilo":#line:171:if str(resulted)=="pilos"or str(resulted)=="pilo":
99
+ resulted ="philo"#line:172:resulted="philo"
100
+ if str (resulted )=="filos"or str (resulted )=="filo":#line:173:if str(resulted)=="filos"or str(resulted)=="filo":
101
+ resulted ="philo"#line:174:resulted="philo"
102
+ if str (resulted )=="sinces"or str (resulted )=="sinc":#line:175:if str(resulted)=="sinces" or str(resulted)=="sinc":
103
+ resulted ="synthe"#line:176:resulted="synthe"
104
+ if str (resulted )=="sintes"or str (resulted )=="sint":#line:177:if str(resulted)=="sintes" or str(resulted)=="sint":
105
+ resulted ="synthe"#line:178:resulted="synthe"
106
+ if str (resulted )=="axos"or str (resulted )=="axo":#line:179:if str(resulted)=="axos" or str(resulted)=="axo":
107
+ resulted ="axso"#line:180:resulted="axso"
108
+ if str (resulted )=="uno":#line:181:if str(resulted)=="uno":
109
+ resulted ="1"#line:182:resulted="1"
110
+ if str (resulted )=="dos"or str (resulted )=="do":#line:184:if str(resulted)=="dos" or str(resulted)=="do":
111
+ resulted ="2"#line:185:resulted="2"
112
+ if str (resulted )=="tres"or str (resulted )=="tr":#line:187:if str(resulted)=="tres" or str(resulted)=="tr":
113
+ resulted ="3"#line:188:resulted="3"
114
+ if str (resulted )=="cuatro"or str (resulted )=="cuatr":#line:190:if str(resulted)=="cuatro"or str(resulted)=="cuatr":
115
+ resulted ="4"#line:191:resulted="4"
116
+ if str (resulted )=="cinco"or str (resulted )=="cinc":#line:193:if str(resulted)=="cinco"or str(resulted)=="cinc":
117
+ resulted ="5"#line:194:resulted="5"
118
+ if str (resulted )=="seis"or str (resulted )=="sei":#line:196:if str(resulted)=="seis"or str(resulted)=="sei":
119
+ resulted ="6"#line:197:resulted="6"
120
+ if str (resulted )=="siete":#line:199:if str(resulted)=="siete":
121
+ resulted ="7"#line:200:resulted="7"
122
+ if str (resulted )=="ocho"or str (resulted )=="och":#line:202:if str(resulted)=="ocho"or str(resulted)=="och":
123
+ resulted ="8"#line:203:resulted="8"
124
+ if str (resulted )=="nueve"or str (resulted )=="nuev":#line:205:if str(resulted)=="nueve"or str(resulted)=="nuev":
125
+ resulted ="9"#line:206:resulted="9"
126
+ if str (resulted )=="cero":#line:208:if str(resulted)=="cero":
127
+ resulted ="0"#line:209:resulted="0"
128
+ if str (remove_accents (word )).lower ()==str (remove_accents (resulted )).lower ():#line:213:if str(remove_accents(word)).lower() == str(remove_accents(resulted)).lower():
129
+ count_words [index1 ]=count_words [index1 ]+1 #line:216:count_words[index1]=count_words[index1]+1
130
+ ls5 [index1 ].pop (index2 )#line:217:ls5[index1].pop(index2)
131
+ indexmax =np .argwhere (count_words ==np .amax (count_words ))#line:219:indexmax = np.argwhere(count_words == np.amax(count_words))
132
+ all_zeros =not np .any (indexmax )#line:220:all_zeros = not np.any(indexmax)
133
+ st .text (count_words )#line:222:st.text(count_words)
134
+ if not np .all (count_words ==0 ):#line:224:if not np.all(count_words==0):
135
+ for indexin in indexmax :#line:226:for indexin in indexmax:
136
+ st .text (indexin )#line:228:st.text(indexin)
137
+ st .text (count_words [indexin ])#line:229:st.text(count_words[indexin])
138
+ st .text ("Si has preguntado...\n")#line:230:st.text("Si has preguntado...\n")
139
+ st .text (df .iloc [indexin ,2 ])#line:231:st.text(df.iloc[indexin,2])
140
+ st .text ("La respuesta es...\n")#line:232:st.text("La respuesta es...\n")
141
+ st .text (df .iloc [indexin ,3 ])#line:233:st.text(df.iloc[indexin,3])
142
+ print ("GRACIAS!")