tayyardurden commited on
Commit
d90493e
·
verified ·
1 Parent(s): 0384994

Upload 75 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from crypto_utils import decrypt_file
3
+ import streamlit as st
4
+
5
+ st.set_page_config(page_title="MS-TTS", page_icon="🤖", layout="wide")
6
+
7
+ # Adjust the path to the encrypted initializer file
8
+ enc_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'enc_main_pages', 'enc_initializer.py'))
9
+
10
+ # Check if the file exists before attempting to decrypt it
11
+ if not os.path.exists(enc_file_path):
12
+ raise FileNotFoundError(f"The file {enc_file_path} does not exist. Please check the path and try again.")
13
+
14
+ # Decrypt and read the content of the encrypted initializer file
15
+ decrypted_content = decrypt_file(enc_file_path)
16
+ exec(decrypted_content)
17
+
18
+ app_starter()
assets/1A.wav ADDED
Binary file (138 kB). View file
 
assets/1B.wav ADDED
Binary file (236 kB). View file
 
assets/1C.wav ADDED
Binary file (111 kB). View file
 
assets/2A.wav ADDED
Binary file (180 kB). View file
 
assets/2B.wav ADDED
Binary file (182 kB). View file
 
assets/2C.wav ADDED
Binary file (189 kB). View file
 
assets/3A.wav ADDED
Binary file (164 kB). View file
 
assets/3B.wav ADDED
Binary file (172 kB). View file
 
assets/3C.wav ADDED
Binary file (185 kB). View file
 
assets/4A.wav ADDED
Binary file (97.9 kB). View file
 
assets/4B.wav ADDED
Binary file (232 kB). View file
 
assets/4C.wav ADDED
Binary file (225 kB). View file
 
assets/5A.wav ADDED
Binary file (207 kB). View file
 
assets/5B.wav ADDED
Binary file (254 kB). View file
 
assets/5C.wav ADDED
Binary file (169 kB). View file
 
assets/6A.wav ADDED
Binary file (214 kB). View file
 
assets/6B.wav ADDED
Binary file (279 kB). View file
 
assets/6C.wav ADDED
Binary file (267 kB). View file
 
assets/7A.wav ADDED
Binary file (601 kB). View file
 
assets/7B.wav ADDED
Binary file (468 kB). View file
 
assets/7C.wav ADDED
Binary file (575 kB). View file
 
assets/8A.wav ADDED
Binary file (162 kB). View file
 
assets/8B.wav ADDED
Binary file (485 kB). View file
 
assets/8C.wav ADDED
Binary file (408 kB). View file
 
assets/9A.wav ADDED
Binary file (365 kB). View file
 
assets/9B.wav ADDED
Binary file (590 kB). View file
 
assets/9C.wav ADDED
Binary file (599 kB). View file
 
crypto_utils.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from cryptography.fernet import Fernet
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables from .env file
7
+ load_dotenv()
8
+
9
+ # Get the ENC_DEC_KEY from the .env file
10
+ ENC_DEC_KEY = os.getenv("ENC_DEC_KEY").encode() # Ensure this is a bytes object
11
+
12
+ @st.cache_data()
13
+ def decrypt_file(file_path):
14
+ fernet = Fernet(ENC_DEC_KEY)
15
+
16
+ with open(file_path, "rb") as file:
17
+ encrypted_data = file.read()
18
+
19
+ decrypted_data = fernet.decrypt(encrypted_data)
20
+ return decrypted_data.decode() # Return the decrypted content as a string
db_utilities/db_connection.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import psycopg2
2
+ import os
3
+ from dotenv import load_dotenv
4
+
5
+ load_dotenv()
6
+
7
+ def create_database():
8
+ db_name = os.getenv('DB_NAME')
9
+ db_user = os.getenv('DB_USER')
10
+ db_password = os.getenv('DB_PASSWORD')
11
+ db_host = os.getenv('DB_HOST', 'localhost')
12
+ db_port = os.getenv('DB_PORT', '5432')
13
+
14
+ print(f"DB_NAME: {db_name}, DB_USER: {db_user}, DB_PASSWORD: {db_password}, DB_HOST: {db_host}, DB_PORT: {db_port}")
15
+
16
+ conn = psycopg2.connect(
17
+ dbname='postgres',
18
+ user=db_user,
19
+ password=db_password,
20
+ host=db_host,
21
+ port=db_port
22
+ )
23
+ conn.autocommit = True
24
+ cursor = conn.cursor()
25
+
26
+ cursor.execute(f"CREATE DATABASE {db_name}")
27
+
28
+ cursor.close()
29
+ conn.close()
30
+
31
+
db_utilities/timer.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import psycopg2
2
+ from dotenv import load_dotenv
3
+ from datetime import timedelta
4
+
5
+ load_dotenv()
6
+
7
+ def get_survey_and_user_id(conn, user_id):
8
+ cursor = conn.cursor()
9
+ cursor.execute('''
10
+ SELECT survey_id, user_id FROM survey_status WHERE user_id = %s
11
+ ''', (user_id,))
12
+ result = cursor.fetchone()
13
+ cursor.close()
14
+ return result
15
+
16
+ def is_question_answered(conn, user_id, sound_name):
17
+ cursor = conn.cursor()
18
+ cursor.execute('''
19
+ SELECT 1 FROM survey_responses WHERE user_id = %s AND sound_name = %s
20
+ ''', (user_id, sound_name))
21
+ result = cursor.fetchone()
22
+ cursor.close()
23
+ return result is not None
24
+
25
+ def get_time_spent(conn, user_id, sound_name):
26
+ cursor = conn.cursor()
27
+ cursor.execute('''
28
+ SELECT time_spent FROM survey_responses WHERE user_id = %s AND sound_name = %s
29
+ ''', (user_id, sound_name))
30
+ result = cursor.fetchone()
31
+ cursor.close()
32
+ return result[0] if result else None
33
+
34
+ def format_time_spent(time_spent):
35
+ total_seconds = time_spent.total_seconds()
36
+ minutes = int(total_seconds // 60)
37
+ seconds = total_seconds % 60
38
+ return f"{minutes} mins {seconds:.2f} secs"
39
+
40
+ def insert_time_spent(conn, user_id, survey_id, sound_name, time_spent):
41
+ cursor = conn.cursor()
42
+ formatted_time_spent = format_time_spent(time_spent)
43
+ try:
44
+ cursor.execute('''
45
+ INSERT INTO survey_timers (user_id, survey_id, sound_table_name, response_id, time_spent)
46
+ VALUES (%s, %s, %s, (SELECT COALESCE(MAX(response_id), 0) + 1 FROM survey_timers), %s)
47
+ ''', (user_id, survey_id, sound_name, formatted_time_spent))
48
+ conn.commit()
49
+ except psycopg2.errors.UniqueViolation:
50
+ conn.rollback()
51
+ finally:
52
+ cursor.close()
53
+
54
+ def get_user_login_time(conn, user_id):
55
+ cursor = conn.cursor()
56
+ cursor.execute('''
57
+ SELECT login_time FROM users WHERE user_id = %s
58
+ ''', (user_id,))
59
+ result = cursor.fetchone()
60
+ cursor.close()
61
+ return result[0] if result else None
62
+
63
+ def calculate_time_spent(conn, user_id):
64
+ result = get_survey_and_user_id(conn, user_id)
65
+ if result is None:
66
+ return
67
+
68
+ survey_id, user_id = result
69
+ sound_names = [f'sound_{i+1}' for i in range(27)] # Assuming 27 sounds
70
+
71
+ previous_time_spent = get_user_login_time(conn, user_id)
72
+
73
+ for sound_name in sound_names:
74
+ if is_question_answered(conn, user_id, sound_name):
75
+ current_time_spent = get_time_spent(conn, user_id, sound_name)
76
+ if previous_time_spent is not None:
77
+ time_spent_difference = current_time_spent - previous_time_spent
78
+ insert_time_spent(conn, user_id, survey_id, sound_name, time_spent_difference)
79
+ previous_time_spent = current_time_spent
enc_main_pages/app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from crypto_utils import decrypt_file
3
+ import streamlit as st
4
+
5
+ st.set_page_config(page_title="MS-TTS", page_icon="🤖", layout="wide")
6
+
7
+ # Construct the absolute path to the encrypted initializer file
8
+ enc_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'ms-tts/enc_main_pages', 'enc_initializer.py'))
9
+
10
+ # Check if the file exists before attempting to decrypt it
11
+ if not os.path.exists(enc_file_path):
12
+ raise FileNotFoundError(f"The file {enc_file_path} does not exist. Please check the path and try again.")
13
+
14
+ # Decrypt and read the content of the encrypted initializer file
15
+ decrypted_content = decrypt_file(enc_file_path)
16
+ exec(decrypted_content)
17
+
18
+ app_starter()
19
+
enc_main_pages/assets/1A.wav ADDED
Binary file (138 kB). View file
 
enc_main_pages/assets/1B.wav ADDED
Binary file (236 kB). View file
 
enc_main_pages/assets/1C.wav ADDED
Binary file (111 kB). View file
 
enc_main_pages/assets/2A.wav ADDED
Binary file (180 kB). View file
 
enc_main_pages/assets/2B.wav ADDED
Binary file (182 kB). View file
 
enc_main_pages/assets/2C.wav ADDED
Binary file (189 kB). View file
 
enc_main_pages/assets/3A.wav ADDED
Binary file (164 kB). View file
 
enc_main_pages/assets/3B.wav ADDED
Binary file (172 kB). View file
 
enc_main_pages/assets/3C.wav ADDED
Binary file (185 kB). View file
 
enc_main_pages/assets/4A.wav ADDED
Binary file (97.9 kB). View file
 
enc_main_pages/assets/4B.wav ADDED
Binary file (232 kB). View file
 
enc_main_pages/assets/4C.wav ADDED
Binary file (225 kB). View file
 
enc_main_pages/assets/5A.wav ADDED
Binary file (207 kB). View file
 
enc_main_pages/assets/5B.wav ADDED
Binary file (254 kB). View file
 
enc_main_pages/assets/5C.wav ADDED
Binary file (169 kB). View file
 
enc_main_pages/assets/6A.wav ADDED
Binary file (214 kB). View file
 
enc_main_pages/assets/6B.wav ADDED
Binary file (279 kB). View file
 
enc_main_pages/assets/6C.wav ADDED
Binary file (267 kB). View file