Skip to content

Commit f78d6c2

Browse files
authored
Merge pull request #1 from rksdutt/master
Python
2 parents b462a57 + 902948d commit f78d6c2

File tree

10 files changed

+224
-25
lines changed

10 files changed

+224
-25
lines changed

AutoComplete_App/backend.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import sqlite3
2+
import json
3+
4+
class AutoComplete:
5+
"""
6+
It works by building a `WordMap` that stores words to word-follower-count
7+
----------------------------
8+
e.g. To train the following statement:
9+
10+
It is not enough to just know how tools work and what they worth,
11+
we have got to learn how to use them and to use them well.
12+
And with all these new weapons in your arsenal, we would better
13+
get those profits fired up
14+
15+
we create the following:
16+
{ It: {is:1}
17+
is: {not:1}
18+
not: {enough:1}
19+
enough: {to:1}
20+
to: {just:1, learn:1, use:2}
21+
just: {know:1}
22+
.
23+
.
24+
profits: {fired:1}
25+
fired: {up:1}
26+
}
27+
so the word completion for "to" will be "use".
28+
For optimization, we use another store `WordPrediction` to save the
29+
predictions for each word
30+
"""
31+
32+
def __init__(self):
33+
"""
34+
Returns - None
35+
Input - None
36+
----------
37+
- Initialize database. we use sqlite3
38+
- Check if the tables exist, if not create them
39+
- maintain a class level access to the database
40+
connection object
41+
"""
42+
self.conn = sqlite3.connect("autocompleteDB.sqlite3", autocommit=True)
43+
cur = self.conn.cursor()
44+
res = cur.execute("SELECT name FROM sqlite_master WHERE name='WordMap'")
45+
tables_exist = res.fetchone()
46+
47+
if not tables_exist:
48+
self.conn.execute("CREATE TABLE WordMap(name TEXT, value TEXT)")
49+
self.conn.execute('CREATE TABLE WordPrediction (name TEXT, value TEXT)')
50+
cur.execute("INSERT INTO WordMap VALUES (?, ?)", ("wordsmap", "{}",))
51+
cur.execute("INSERT INTO WordPrediction VALUES (?, ?)", ("predictions", "{}",))
52+
53+
def train(self, sentence):
54+
"""
55+
Returns - string
56+
Input - str: a string of words called sentence
57+
----------
58+
Trains the sentence. It does this by creating a map of
59+
current words to next words and their counts for each
60+
time the next word appears after the current word
61+
- takes in the sentence and splits it into a list of words
62+
- retrieves the word map and predictions map
63+
- creates the word map and predictions map together
64+
- saves word map and predictions map to the database
65+
"""
66+
cur = self.conn.cursor()
67+
words_list = sentence.split(" ")
68+
69+
words_map = cur.execute("SELECT value FROM WordMap WHERE name='wordsmap'").fetchone()[0]
70+
words_map = json.loads(words_map)
71+
72+
predictions = cur.execute("SELECT value FROM WordPrediction WHERE name='predictions'").fetchone()[0]
73+
predictions = json.loads(predictions)
74+
75+
for idx in range(len(words_list)-1):
76+
curr_word, next_word = words_list[idx], words_list[idx+1]
77+
if curr_word not in words_map:
78+
words_map[curr_word] = {}
79+
if next_word not in words_map[curr_word]:
80+
words_map[curr_word][next_word] = 1
81+
else:
82+
words_map[curr_word][next_word] += 1
83+
84+
# checking the completion word against the next word
85+
if curr_word not in predictions:
86+
predictions[curr_word] = {
87+
'completion_word': next_word,
88+
'completion_count': 1
89+
}
90+
else:
91+
if words_map[curr_word][next_word] > predictions[curr_word]['completion_count']:
92+
predictions[curr_word]['completion_word'] = next_word
93+
predictions[curr_word]['completion_count'] = words_map[curr_word][next_word]
94+
95+
words_map = json.dumps(words_map)
96+
predictions = json.dumps(predictions)
97+
98+
cur.execute("UPDATE WordMap SET value = (?) WHERE name='wordsmap'", (words_map,))
99+
cur.execute("UPDATE WordPrediction SET value = (?) WHERE name='predictions'", (predictions,))
100+
return("training complete")
101+
102+
def predict(self, word):
103+
"""
104+
Returns - string
105+
Input - string
106+
----------
107+
Returns the completion word of the input word
108+
- takes in a word
109+
- retrieves the predictions map
110+
- returns the completion word of the input word
111+
"""
112+
cur = self.conn.cursor()
113+
predictions = cur.execute("SELECT value FROM WordPrediction WHERE name='predictions'").fetchone()[0]
114+
predictions = json.loads(predictions)
115+
completion_word = predictions[word.lower()]['completion_word']
116+
return completion_word
117+
118+
119+
120+
if __name__ == "__main__":
121+
input_ = "It is not enough to just know how tools work and what they worth,\
122+
we have got to learn how to use them and to use them well. And with\
123+
all these new weapons in your arsenal, we would better get those profits fired up"
124+
ac = AutoComplete()
125+
ac.train(input_)
126+
print(ac.predict("to"))

AutoComplete_App/frontend.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from tkinter import *
2+
from tkinter import messagebox
3+
import backend
4+
5+
6+
def train():
7+
sentence = train_entry.get()
8+
ac = backend.AutoComplete()
9+
ac.train(sentence)
10+
11+
def predict_word():
12+
word = predict_word_entry.get()
13+
ac = backend.AutoComplete()
14+
print(ac.predict(word))
15+
16+
if __name__ == "__main__":
17+
root = Tk()
18+
root.title("Input note")
19+
root.geometry('300x300')
20+
21+
train_label = Label(root, text="Train")
22+
train_label.pack()
23+
train_entry = Entry(root)
24+
train_entry.pack()
25+
26+
train_button = Button(root, text="train", command=train)
27+
train_button.pack()
28+
29+
predict_word_label = Label(root, text="Input term to predict")
30+
predict_word_label.pack()
31+
predict_word_entry = Entry(root)
32+
predict_word_entry.pack()
33+
34+
predict_button = Button(root, text="predict", command=predict_word)
35+
predict_button.pack()
36+
37+
root.mainloop()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
numpy==1.26.4
2-
opencv_python==4.9.0.80
3-
mediapipe==0.10.9
1+
numpy==2.0.0
2+
opencv_python==4.10.0.82
3+
mediapipe==0.10.14

ImageDownloader/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
requests==2.31.0
1+
requests==2.32.3

PDF/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Pillow==10.2.0
1+
Pillow==10.3.0
22
fpdf==1.7.2
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
colorama==0.4.6
2-
inquirer==3.2.4
2+
inquirer==3.2.5

add_two_number.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
user_input = (input("type type 'start' to run program:")).lower()
2+
3+
if user_input == 'start':
4+
is_game_running = True
5+
else:
6+
is_game_running = False
7+
8+
9+
while (is_game_running):
10+
num1 = int(input("enter number 1:"))
11+
num2 = int(input("enter number 2:"))
12+
num3 = num1+num2
13+
print(f"sum of {num1} and {num2} is {num3}")
14+
user_input = (input("if you want to discontinue type 'stop':")).lower()
15+
if user_input == "stop":
16+
is_game_running = False
17+

async_downloader/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
aiohttp==3.9.3
1+
aiohttp==3.9.5
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def degrees_to_compass(degrees):
2+
directions = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
3+
index = round(degrees / 45) % 8
4+
return directions[index]
5+
6+
# Taking input from the user
7+
while True:
8+
try:
9+
degrees = float(input("Enter the wind direction in degrees (0-359): "))
10+
if degrees < 0 or degrees >= 360:
11+
raise ValueError("Degrees must be between 0 and 359")
12+
break
13+
except ValueError as ve:
14+
print(f"Error: {ve}")
15+
continue
16+
17+
18+
compass_direction = degrees_to_compass(degrees)
19+
print(f"{degrees} degrees is {compass_direction}")

requirements_with_versions.txt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pafy==0.5.5
2-
aiohttp==3.9.3
2+
aiohttp==3.9.5
33
fuzzywuzzy==0.18.0
44
hupper==1.12.1
55
seaborn==0.13.2
@@ -15,58 +15,58 @@ dictator==0.3.1
1515
caller==0.0.2
1616
watchdog==3.0.0
1717
PyQt5==5.15.10
18-
numpy==1.26.4
18+
numpy==2.0.0
1919
fileinfo==0.3.3
2020
backend==0.2.4.1
2121
win10toast==0.9
2222
Counter==1.0.0
2323
Flask==3.0.2
2424
selenium==4.16.0
2525
firebase-admin==6.5.0
26-
ujson==5.9.0
27-
requests==2.31.0
26+
ujson==5.10.0
27+
requests==2.32.3
2828
quo==2023.5.1
2929
PyPDF2==3.0.1
3030
pyserial==3.5
31-
twilio==9.0.0
31+
twilio==9.1.1
3232
tabula==1.0.5
3333
nltk==3.8.1
34-
Pillow==10.2.0
34+
Pillow==10.3.0
3535
SocksiPy-branch==1.01
3636
xlrd==2.0.1
3737
fpdf==1.7.2
3838
mysql-connector-repackaged==0.3.1
3939
word2number==1.1
40-
tornado==6.4
40+
tornado==6.4.1
4141
obs==0.0.0
4242
todo==0.1
4343
oauth2client==4.1.3
4444
keras==3.3.3
45-
pymongo==4.7.1
45+
pymongo==4.7.3
4646
playsound==1.3.0
4747
pyttsx3==2.90
4848
auto-mix-prep==0.2.0
4949
lib==4.0.0
5050
pywifi==1.1.12
5151
patterns==0.3
52-
openai==1.9.0
52+
openai==1.33.0
5353
background==0.2.1
54-
pydantic==2.6.1
54+
pydantic==2.7.3
5555
openpyxl==3.1.2
5656
pytesseract==0.3.10
5757
requests-mock==1.12.1
5858
pyglet==2.0.10
5959
urllib3==2.2.1
60-
thirdai==0.7.44
61-
google-api-python-client==2.115.0
60+
thirdai==0.8.5
61+
google-api-python-client==2.133.0
6262
sound==0.1.0
6363
xlwt==1.3.0
6464
pygame==2.5.2
6565
speechtotext==0.0.3
6666
wikipedia==1.4.0
6767
tqdm==4.66.4
6868
Menu==3.2.2
69-
yfinance==0.2.35
69+
yfinance==0.2.40
7070
tweepy==4.14.0
7171
tkcalendar==1.6.1
7272
pytube==15.0.0
@@ -81,7 +81,7 @@ Unidecode==1.3.8
8181
Ball==0.2.9
8282
pynput==1.7.6
8383
gTTS==2.5.0
84-
ccxt==4.3.18
84+
ccxt==4.3.48
8585
fitz==0.0.1.dev2
8686
fastapi==0.109.0
8787
Django==5.0.5
@@ -94,18 +94,18 @@ PyQRCode==1.2.1
9494
freegames==2.5.3
9595
pyperclip==1.8.2
9696
newspaper==0.1.0.7
97-
opencv-python==4.9.0.80
97+
opencv-python==4.10.0.82
9898
tensorflow==2.15.0.post1
9999
pandas==2.2.2
100-
pytest==8.2.0
100+
pytest==8.2.2
101101
qrcode==7.4.2
102102
googletrans==3.0.0
103103
slab==1.1.5
104104
psutil==5.9.8
105-
mediapipe==0.10.9
105+
mediapipe==0.10.14
106106
rich==13.7.1
107107
httplib2==0.22.0
108-
protobuf==4.25.2
108+
protobuf==5.27.1
109109
colorama==0.4.6
110110
plyer==2.1.0
111111
Flask-Ask==0.9.8

0 commit comments

Comments
 (0)