Merlintxu commited on
Commit
635422f
1 Parent(s): 03eeedd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -41
app.py CHANGED
@@ -1,45 +1,29 @@
1
- from transformers import pipeline
2
- import gradio as gr
3
- import pygame
4
 
5
- # Load the pre-trained Spanish language model using HuggingFace
6
- nlp = pipeline("text2text-generation", model="datificate/gpt2-small-spanish")
7
 
8
- # Define a function that generates a random Spanish sentence using the pre-trained model
9
- def generate_sentence():
10
- sentence = nlp("Genera una oración en español")[0]["generated_text"]
11
- return sentence
12
 
13
- # Define a function that checks if the child identifies the verb in the sentence
14
- def check_answer(sentence, verb):
15
- words = sentence.split()
16
- if verb in words:
17
- return "¡Correcto! El verbo está en la oración."
18
  else:
19
- return "Lo siento, el verbo no está en la oración."
20
-
21
- # Define a function that creates the chatbot interface using Gradio and adds fun animations or sound effects
22
- def chatbot():
23
- # Initialize pygame mixer for sound effects
24
- pygame.mixer.init()
25
-
26
- # Load sound effect
27
- sound_effect = pygame.mixer.Sound("ding.wav")
28
-
29
- # Generate a random sentence
30
- sentence = generate_sentence()
31
-
32
- # Ask the child to identify the verb in the sentence
33
- verb = input("Identifica el verbo en la siguiente oración: " + sentence + "\n")
34
-
35
- # Check if the child's answer is correct
36
- result = check_answer(sentence, verb)
37
-
38
- # Play sound effect if the answer is correct
39
- if "Correcto" in result:
40
- sound_effect.play()
41
-
42
- return result
43
-
44
- # Run the chatbot interface using Gradio
45
- gr.Interface(fn=chatbot, inputs=None, outputs="text").launch()
 
1
+ import streamlit as st
2
+ import spacy
 
3
 
4
+ nlp = spacy.load('es_core_news_sm')
 
5
 
6
+ def identify_pos(sentence):
7
+ doc = nlp(sentence)
8
+ pos_tags = [(token.text, token.pos_) for token in doc]
9
+ return pos_tags
10
 
11
+ def game_logic(sentence, user_input):
12
+ correct_answers = identify_pos(sentence)
13
+ if user_input in correct_answers:
14
+ return True
 
15
  else:
16
+ return False
17
+
18
+ def main():
19
+ st.title('Juego de gramática española')
20
+ sentence = st.text_input('Introduce una frase:')
21
+ user_input = st.text_input('Identifica una palabra en la frase:')
22
+ if sentence and user_input:
23
+ if game_logic(sentence, user_input):
24
+ st.success('¡Correcto!')
25
+ else:
26
+ st.error('Incorrecto. Intenta de nuevo.')
27
+
28
+ if __name__ == "__main__":
29
+ main()