Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,30 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
from kommunicate import Kommunicate
|
| 4 |
|
| 5 |
-
|
| 6 |
-
nlp = spacy.load('es_core_news_sm')
|
| 7 |
|
| 8 |
-
|
| 9 |
-
pos_map = {
|
| 10 |
-
'sustantivo': 'NOUN',
|
| 11 |
-
'verbo': 'VERB',
|
| 12 |
-
'adjetivo': 'ADJ',
|
| 13 |
-
'art铆culo': 'DET'
|
| 14 |
-
}
|
| 15 |
|
| 16 |
-
|
| 17 |
-
def
|
| 18 |
-
|
| 19 |
-
pos_tags = [(token.text, token.pos_) for token in doc]
|
| 20 |
-
return pos_tags
|
| 21 |
|
| 22 |
-
|
| 23 |
-
def
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
if pos.lower() == user_pos.lower():
|
| 29 |
-
return True, f'隆Correcto! "{user_word}" es un {user_pos}.'
|
| 30 |
-
else:
|
| 31 |
-
return False, f'Incorrecto. "{user_word}" no es un {user_pos}, es un {pos}.'
|
| 32 |
-
return False, f'La palabra "{user_word}" no se encuentra en la frase.'
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
correct, message = game_logic(sentence, user_word, user_pos)
|
| 38 |
-
return message
|
| 39 |
-
else:
|
| 40 |
-
return 'Por favor, introduce una frase, una palabra y selecciona una funci贸n gramatical v谩lida (sustantivo, verbo, adjetivo, art铆culo).'
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
iface.launch()
|
|
|
|
| 1 |
+
from flask import Flask, request, render_template
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
+
app = Flask(__name__)
|
|
|
|
| 5 |
|
| 6 |
+
nlp = pipeline('sentiment-analysis')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
@app.route('/')
|
| 9 |
+
def home():
|
| 10 |
+
return render_template('index.html')
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
@app.route('/predict',methods=['POST'])
|
| 13 |
+
def predict():
|
| 14 |
+
if request.method == 'POST':
|
| 15 |
+
message = request.form['message']
|
| 16 |
+
prediction = nlp(message)
|
| 17 |
+
return render_template('index.html', prediction_text=prediction)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
if __name__ == "__main__":
|
| 20 |
+
app.run(debug=True)
|
| 21 |
+
from transformers import GPT3LMHeadModel, GPT2Tokenizer
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
| 24 |
+
model = GPT3LMHeadModel.from_pretrained("gpt3")
|
| 25 |
+
|
| 26 |
+
def get_response(prompt):
|
| 27 |
+
inputs = tokenizer.encode(prompt, return_tensors="pt")
|
| 28 |
+
outputs = model.generate(inputs, max_length=150, num_return_sequences=1, no_repeat_ngram_size=2)
|
| 29 |
+
response = tokenizer.decode(outputs[:, inputs.shape[-1]:][0], skip_special_tokens=True)
|
| 30 |
+
return response
|
|
|