GramAPP / app.py
Merlintxu's picture
Update app.py
7b823d4
raw
history blame
782 Bytes
import streamlit as st
import spacy
nlp = spacy.load('es_core_news_sm')
def identify_pos(sentence):
doc = nlp(sentence)
pos_tags = [(token.text, token.pos_) for token in doc]
return pos_tags
def game_logic(sentence, user_input):
correct_answers = identify_pos(sentence)
if user_input in correct_answers:
return True
else:
return False
def main():
st.title('Juego de gramática española')
sentence = st.text_input('Introduce una frase:')
user_input = st.text_input('Identifica una palabra en la frase:')
if sentence and user_input:
if game_logic(sentence, user_input):
st.success('¡Correcto!')
else:
st.error('Incorrecto. Intenta de nuevo.')
if __name__ == "__main__":
main()