Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit af783b5

Browse files
committed
Fix code style issues with Black
1 parent d877c5a commit af783b5

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

projects/SMS_ChatBot/main.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@
88

99
app = Flask(__name__)
1010

11-
@app.route("/sms", methods=['POST'])
11+
12+
@app.route("/sms", methods=["POST"])
1213
def chatgpt():
1314
# Get the incoming SMS message
14-
inb_msg = request.form['Body'].lower()
15+
inb_msg = request.form["Body"].lower()
1516

1617
# Print the incoming message for debugging
1718
print(inb_msg)
1819

1920
# Use the OpenAI API to generate a response
2021
response = openai.Completion.create(
21-
model="gpt-3.5-turbo",
22-
prompt=inb_msg,
23-
max_tokens=3000,
24-
temperature=0.7
22+
model="gpt-3.5-turbo", prompt=inb_msg, max_tokens=3000, temperature=0.7
2523
)
2624

2725
# Create a response using Twilio's MessagingResponse
@@ -30,6 +28,7 @@ def chatgpt():
3028

3129
return str(resp)
3230

31+
3332
if __name__ == "__main__":
3433
# Run the Flask app in debug mode
3534
app.run(debug=True)

projects/Word_Predictor/main.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import pandas as pd
2020

21+
2122
class WhatsAppChat:
2223
def __init__(self, filename):
2324
# Initialize the object by reading in the chat file, and counting word frequency and next words
@@ -44,8 +45,9 @@ def count_word_frequency(self):
4445
else:
4546
word_freq_dict[word] = 1
4647
# Sort the word frequency dictionary by value in descending order and return it
47-
sorted_word_freq_dict = dict(sorted(word_freq_dict.items(),
48-
key=lambda x: -1*int(x[1])))
48+
sorted_word_freq_dict = dict(
49+
sorted(word_freq_dict.items(), key=lambda x: -1 * int(x[1]))
50+
)
4951
return sorted_word_freq_dict
5052

5153
def find_next_words(self):
@@ -57,7 +59,7 @@ def find_next_words(self):
5759
for i in range(len(words)):
5860
if i != len(words) - 1:
5961
current_word = words[i]
60-
next_word = words[i+1].replace("\n", "")
62+
next_word = words[i + 1].replace("\n", "")
6163
if current_word in next_words_dict:
6264
if next_word in next_words_dict[current_word]:
6365
next_words_dict[current_word][next_word] += 1
@@ -80,20 +82,21 @@ def predict_next_word(self, current_word):
8082
if current_word in self.chat.next_words_dict:
8183
# Get the dictionary of next words for the current word and sort it by frequency
8284
next_word_freq_dict = self.chat.next_words_dict[current_word]
83-
sorted_next_words = sorted(next_word_freq_dict.items(),
84-
key=lambda x: x[1],
85-
reverse=True)
85+
sorted_next_words = sorted(
86+
next_word_freq_dict.items(), key=lambda x: x[1], reverse=True
87+
)
8688
# Get the top num_predictions words and return them
87-
next_words = [word[0] for word in sorted_next_words[:self.num_predictions]]
89+
next_words = [word[0] for word in sorted_next_words[: self.num_predictions]]
8890
return next_words
8991
else:
9092
# If the current word is not in the dictionary of next words, return None
9193
return None
9294

95+
9396
# Create a WhatsAppChat object and a NextWordPredictor object after loading Chats.txt file
9497
# set n as the length of words you want to predict after a given word
95-
chat = WhatsAppChat('Chats.txt')
96-
n, given_word = 3, 'good'
98+
chat = WhatsAppChat("Chats.txt")
99+
n, given_word = 3, "good"
97100
predictor = NextWordPredictor(chat, num_predictions=n)
98101

99102
# This prints the next n word predictions after the given_word

0 commit comments

Comments
 (0)