Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| from bokeh.models.widgets import Button | |
| from bokeh.models import CustomJS | |
| from streamlit_bokeh_events import streamlit_bokeh_events | |
| # Load pandas | |
| import pandas as pd | |
| import numpy as np | |
| from nltk.stem import SnowballStemmer | |
| df = pd.read_excel('preguntas_qh_tags.xlsx',engine="openpyxl") | |
| #var recognition = new webkitSpeechRecognition(); | |
| precission=50 | |
| precission = st.text_input('Input % of tags in sentence (0-100):') | |
| stt_button = Button(label="Speak")#, width=100) | |
| #stt_button = st.button(label="Speak") | |
| 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(); | |
| """)) | |
| result = streamlit_bokeh_events( | |
| stt_button, | |
| events="GET_TEXT", | |
| key="listen", | |
| refresh_on_update=False, | |
| override_height=75, | |
| debounce_time=0) | |
| #import QuirohelpTagsMethod as QHT | |
| placeholder = st.empty() | |
| # Replace the placeholder with some text: | |
| placeholder.text("Escuchando...") | |
| if result: | |
| if "GET_TEXT" in result: | |
| #result2=QHT.Look4tag(result.get("GET_TEXT")) | |
| placeholder.text("Entendido!") | |
| # Clear all those elements: | |
| placeholder.empty() | |
| st.write(result.get("GET_TEXT")) | |
| #st.write(result2) | |
| #st.write("PEDRO") | |
| spanish_stemmer = SnowballStemmer('spanish') | |
| query=(spanish_stemmer.stem(result.get("GET_TEXT"))) | |
| list_words=[] | |
| st.text(query) | |
| textresult=str("") | |
| for index,row in df.iterrows(): | |
| list_words=df.loc[index,'TAGS'] | |
| list_words = list_words.translate({ ord("?"): None }) | |
| list_words = list_words.translate({ ord("¿"): None }) | |
| ls = list_words.split(",") | |
| ls = [string for string in ls if string != ""] | |
| number_of_tags=len(ls) | |
| found=True | |
| words_found=0 | |
| for word in ls : | |
| if (spanish_stemmer.stem(word)) in query:# and found==True: | |
| found=True | |
| words_found=words_found+1 | |
| else: | |
| found=False | |
| #if found==True: | |
| #IF WE FIND MORE THAN A HALF OF THE TAGS, THEN WE SHOW THE ANSWER (IT COULD BE MORE THAN JUST ONE ANSWER) | |
| if (words_found/number_of_tags)>(int(precission)/100):#0.5: | |
| st.text("##############################################################") | |
| st.text("Si has preguntado...\n") | |
| st.text(df.iloc[index,1]) | |
| st.text("La respuesta es...\n") | |
| st.text(df.iloc[index,2]) | |
| st.text("##############################################################") | |
| # streamlit run C:\Users\15572890\Desktop\StockPrediction\Coding\CorrelacionStocks\APIS-StockPlatforms\APIs\QuiroHelpNLP\QuirohelpWeb.py | |