Update app.py
Browse files
app.py
CHANGED
@@ -11,10 +11,20 @@ from nltk.stem import PorterStemmer
|
|
11 |
from nltk.stem import WordNetLemmatizer
|
12 |
import tensorflow as tf
|
13 |
from tensorflow import keras
|
|
|
14 |
|
15 |
nltk.download('punkt')
|
16 |
nltk.download('wordnet')
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
app = Flask(__name__)
|
19 |
|
20 |
# Load the JSON data from the file
|
@@ -25,15 +35,17 @@ with open('info.txt', 'r') as file:
|
|
25 |
database_content = file.read()
|
26 |
database_tag = database_content
|
27 |
|
|
|
|
|
28 |
template = "Message: {message}\n\nConversation History: {history}\n\nDate and Time: {date_time}\n\nBitcoin Price: ${bitcoin_price}\n\nBitcoin history from 1-jan-2024 to today: {database_tag}\n\nYour system: {json_data}.\n\nResponse:"
|
29 |
prompt = PromptTemplate(template=template, input_variables=["message","history", "date_time", "bitcoin_price", "database_tag", "json_data"])
|
30 |
conversation_history = []
|
31 |
|
32 |
-
MAX_HISTORY_LENGTH = 55
|
33 |
|
34 |
def update_conversation_history(message):
|
35 |
if len(conversation_history) >= MAX_HISTORY_LENGTH:
|
36 |
-
conversation_history.pop(0)
|
37 |
conversation_history.append(message)
|
38 |
|
39 |
def get_bitcoin_price():
|
@@ -61,7 +73,11 @@ def index():
|
|
61 |
def submit():
|
62 |
user_input = request.json.get('user_input')
|
63 |
|
64 |
-
|
|
|
|
|
|
|
|
|
65 |
ps = PorterStemmer()
|
66 |
stemmed_tokens = [ps.stem(token) for token in tokens]
|
67 |
|
|
|
11 |
from nltk.stem import WordNetLemmatizer
|
12 |
import tensorflow as tf
|
13 |
from tensorflow import keras
|
14 |
+
import spacy
|
15 |
|
16 |
nltk.download('punkt')
|
17 |
nltk.download('wordnet')
|
18 |
|
19 |
+
def download_spacy_model():
|
20 |
+
try:
|
21 |
+
spacy.load("en_core_web_sm")
|
22 |
+
except OSError:
|
23 |
+
import spacy.cli
|
24 |
+
spacy.cli.download("en_core_web_sm")
|
25 |
+
|
26 |
+
download_spacy_model()
|
27 |
+
|
28 |
app = Flask(__name__)
|
29 |
|
30 |
# Load the JSON data from the file
|
|
|
35 |
database_content = file.read()
|
36 |
database_tag = database_content
|
37 |
|
38 |
+
nlp = spacy.load("en_core_web_sm")
|
39 |
+
|
40 |
template = "Message: {message}\n\nConversation History: {history}\n\nDate and Time: {date_time}\n\nBitcoin Price: ${bitcoin_price}\n\nBitcoin history from 1-jan-2024 to today: {database_tag}\n\nYour system: {json_data}.\n\nResponse:"
|
41 |
prompt = PromptTemplate(template=template, input_variables=["message","history", "date_time", "bitcoin_price", "database_tag", "json_data"])
|
42 |
conversation_history = []
|
43 |
|
44 |
+
MAX_HISTORY_LENGTH = 55
|
45 |
|
46 |
def update_conversation_history(message):
|
47 |
if len(conversation_history) >= MAX_HISTORY_LENGTH:
|
48 |
+
conversation_history.pop(0)
|
49 |
conversation_history.append(message)
|
50 |
|
51 |
def get_bitcoin_price():
|
|
|
73 |
def submit():
|
74 |
user_input = request.json.get('user_input')
|
75 |
|
76 |
+
doc = nlp(user_input)
|
77 |
+
tokens = [token.text for token in doc]
|
78 |
+
|
79 |
+
# Add Spacy NLP processing here
|
80 |
+
|
81 |
ps = PorterStemmer()
|
82 |
stemmed_tokens = [ps.stem(token) for token in tokens]
|
83 |
|