Upload 2 files
Browse filesInitiated conversational DB based on MySQL
- conversationDB.py +53 -0
- requirements.txt +4 -1
conversationDB.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import paramiko
|
2 |
+
import pymysql
|
3 |
+
from sshtunnel import SSHTunnelForwarder
|
4 |
+
|
5 |
+
# SSH settings
|
6 |
+
ssh_host = '129.159.146.88'
|
7 |
+
ssh_user = 'ubuntu'
|
8 |
+
ssh_key_path = 'C:/Users/kerts/OneDrive/Documents/Keys/Ubuntu_Oracle/ssh-key-2023-02-12.key'
|
9 |
+
|
10 |
+
# MySQL settings
|
11 |
+
mysql_host = 'localhost' # because we will connect through the SSH tunnel
|
12 |
+
mysql_port = 3306 # the default MySQL port
|
13 |
+
mysql_user = 'root'
|
14 |
+
mysql_password = 'naP2tion'
|
15 |
+
mysql_db = 'warbot'
|
16 |
+
|
17 |
+
# create an SSH client and load the private key
|
18 |
+
ssh_client = paramiko.SSHClient()
|
19 |
+
ssh_client.load_system_host_keys()
|
20 |
+
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
21 |
+
private_key = paramiko.RSAKey.from_private_key_file(ssh_key_path)
|
22 |
+
|
23 |
+
# start the SSH tunnel using sshtunnel
|
24 |
+
with SSHTunnelForwarder(
|
25 |
+
(ssh_host, 22),
|
26 |
+
ssh_username=ssh_user,
|
27 |
+
ssh_pkey=private_key,
|
28 |
+
remote_bind_address=(mysql_host, mysql_port)) as tunnel:
|
29 |
+
|
30 |
+
# connect to the MySQL server through the SSH tunnel
|
31 |
+
mysql_conn = pymysql.connect(
|
32 |
+
host='localhost',
|
33 |
+
port=tunnel.local_bind_port,
|
34 |
+
user=mysql_user,
|
35 |
+
password=mysql_password,
|
36 |
+
db=mysql_db
|
37 |
+
)
|
38 |
+
|
39 |
+
# send a query to the MySQL database and print the response table
|
40 |
+
with mysql_conn.cursor() as cursor:
|
41 |
+
query = 'SELECT * FROM conversations WHERE username = "user1";'
|
42 |
+
cursor.execute(query)
|
43 |
+
rows = cursor.fetchall()
|
44 |
+
for row in rows:
|
45 |
+
print(row)
|
46 |
+
|
47 |
+
# close the MySQL connection
|
48 |
+
mysql_conn.close()
|
49 |
+
|
50 |
+
# close the SSH client
|
51 |
+
ssh_client.close()
|
52 |
+
|
53 |
+
# query = 'SELECT * FROM conversations WHERE username = "user1";'
|
requirements.txt
CHANGED
@@ -4,9 +4,12 @@ bs4
|
|
4 |
transformers
|
5 |
scikit-learn
|
6 |
tensorboardX
|
7 |
-
gradio
|
8 |
schedule
|
9 |
tqdm
|
10 |
pyspellchecker
|
|
|
|
|
|
|
11 |
#pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu116
|
12 |
#pip install torch==1.13.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117
|
|
|
4 |
transformers
|
5 |
scikit-learn
|
6 |
tensorboardX
|
7 |
+
#gradio
|
8 |
schedule
|
9 |
tqdm
|
10 |
pyspellchecker
|
11 |
+
paramiko
|
12 |
+
pymysql
|
13 |
+
sshtunnel
|
14 |
#pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu116
|
15 |
#pip install torch==1.13.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117
|