nathanieluriri
commited on
Commit
·
78240ec
0
Parent(s):
initial commit
Browse files- .gitignore +176 -0
- app.py +48 -0
- chating.py +97 -0
- database.py +149 -0
- requirements.txt +0 -0
- variables.py +91 -0
.gitignore
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Created by https://www.toptal.com/developers/gitignore/api/python
|
2 |
+
# Edit at https://www.toptal.com/developers/gitignore?templates=python
|
3 |
+
|
4 |
+
### Python ###
|
5 |
+
# Byte-compiled / optimized / DLL files
|
6 |
+
__pycache__/
|
7 |
+
*.py[cod]
|
8 |
+
*$py.class
|
9 |
+
|
10 |
+
# C extensions
|
11 |
+
*.so
|
12 |
+
|
13 |
+
# Distribution / packaging
|
14 |
+
.Python
|
15 |
+
build/
|
16 |
+
develop-eggs/
|
17 |
+
dist/
|
18 |
+
downloads/
|
19 |
+
eggs/
|
20 |
+
.eggs/
|
21 |
+
lib/
|
22 |
+
lib64/
|
23 |
+
parts/
|
24 |
+
sdist/
|
25 |
+
var/
|
26 |
+
wheels/
|
27 |
+
share/python-wheels/
|
28 |
+
*.egg-info/
|
29 |
+
.installed.cfg
|
30 |
+
*.egg
|
31 |
+
MANIFEST
|
32 |
+
|
33 |
+
# PyInstaller
|
34 |
+
# Usually these files are written by a python script from a template
|
35 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
36 |
+
*.manifest
|
37 |
+
*.spec
|
38 |
+
|
39 |
+
# Installer logs
|
40 |
+
pip-log.txt
|
41 |
+
pip-delete-this-directory.txt
|
42 |
+
|
43 |
+
# Unit test / coverage reports
|
44 |
+
htmlcov/
|
45 |
+
.tox/
|
46 |
+
.nox/
|
47 |
+
.coverage
|
48 |
+
.coverage.*
|
49 |
+
.cache
|
50 |
+
nosetests.xml
|
51 |
+
coverage.xml
|
52 |
+
*.cover
|
53 |
+
*.py,cover
|
54 |
+
.hypothesis/
|
55 |
+
.pytest_cache/
|
56 |
+
cover/
|
57 |
+
|
58 |
+
# Translations
|
59 |
+
*.mo
|
60 |
+
*.pot
|
61 |
+
|
62 |
+
# Django stuff:
|
63 |
+
*.log
|
64 |
+
local_settings.py
|
65 |
+
db.sqlite3
|
66 |
+
db.sqlite3-journal
|
67 |
+
|
68 |
+
# Flask stuff:
|
69 |
+
instance/
|
70 |
+
.webassets-cache
|
71 |
+
|
72 |
+
# Scrapy stuff:
|
73 |
+
.scrapy
|
74 |
+
|
75 |
+
# Sphinx documentation
|
76 |
+
docs/_build/
|
77 |
+
|
78 |
+
# PyBuilder
|
79 |
+
.pybuilder/
|
80 |
+
target/
|
81 |
+
|
82 |
+
# Jupyter Notebook
|
83 |
+
.ipynb_checkpoints
|
84 |
+
|
85 |
+
# IPython
|
86 |
+
profile_default/
|
87 |
+
ipython_config.py
|
88 |
+
|
89 |
+
# pyenv
|
90 |
+
# For a library or package, you might want to ignore these files since the code is
|
91 |
+
# intended to run in multiple environments; otherwise, check them in:
|
92 |
+
# .python-version
|
93 |
+
|
94 |
+
# pipenv
|
95 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
96 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
97 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
98 |
+
# install all needed dependencies.
|
99 |
+
#Pipfile.lock
|
100 |
+
|
101 |
+
# poetry
|
102 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
103 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
104 |
+
# commonly ignored for libraries.
|
105 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
106 |
+
#poetry.lock
|
107 |
+
|
108 |
+
# pdm
|
109 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
110 |
+
#pdm.lock
|
111 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
112 |
+
# in version control.
|
113 |
+
# https://pdm.fming.dev/#use-with-ide
|
114 |
+
.pdm.toml
|
115 |
+
|
116 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
117 |
+
__pypackages__/
|
118 |
+
|
119 |
+
# Celery stuff
|
120 |
+
celerybeat-schedule
|
121 |
+
celerybeat.pid
|
122 |
+
|
123 |
+
# SageMath parsed files
|
124 |
+
*.sage.py
|
125 |
+
|
126 |
+
# Environments
|
127 |
+
.env
|
128 |
+
.venv
|
129 |
+
env/
|
130 |
+
venv/
|
131 |
+
ENV/
|
132 |
+
env.bak/
|
133 |
+
venv.bak/
|
134 |
+
|
135 |
+
# Spyder project settings
|
136 |
+
.spyderproject
|
137 |
+
.spyproject
|
138 |
+
|
139 |
+
# Rope project settings
|
140 |
+
.ropeproject
|
141 |
+
|
142 |
+
# mkdocs documentation
|
143 |
+
/site
|
144 |
+
|
145 |
+
# mypy
|
146 |
+
.mypy_cache/
|
147 |
+
.dmypy.json
|
148 |
+
dmypy.json
|
149 |
+
|
150 |
+
# Pyre type checker
|
151 |
+
.pyre/
|
152 |
+
|
153 |
+
# pytype static type analyzer
|
154 |
+
.pytype/
|
155 |
+
|
156 |
+
# Cython debug symbols
|
157 |
+
cython_debug/
|
158 |
+
|
159 |
+
# PyCharm
|
160 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
161 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
162 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
163 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
164 |
+
#.idea/
|
165 |
+
|
166 |
+
### Python Patch ###
|
167 |
+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
168 |
+
poetry.toml
|
169 |
+
|
170 |
+
# ruff
|
171 |
+
.ruff_cache/
|
172 |
+
|
173 |
+
# LSP config files
|
174 |
+
pyrightconfig.json
|
175 |
+
|
176 |
+
# End of https://www.toptal.com/developers/gitignore/api/python
|
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from chating import display_previous_chats, user, bot_response, generate_bar_chart
|
3 |
+
from variables import thinnk
|
4 |
+
|
5 |
+
|
6 |
+
st.set_page_config("Project", page_icon=":books:", layout="wide")
|
7 |
+
|
8 |
+
# Simulated authentication state
|
9 |
+
auth_state = True # Simulating authentication by default
|
10 |
+
hide_streamlit_style = """
|
11 |
+
<style>
|
12 |
+
#MainMenu {visibility: hidden;}
|
13 |
+
footer {visibility: hidden;}
|
14 |
+
.viewerBadge_link__qRIco{display:None;}
|
15 |
+
</style>
|
16 |
+
"""
|
17 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
18 |
+
if "messages" not in st.session_state:
|
19 |
+
st.session_state.messages = []
|
20 |
+
# Simulated user_info
|
21 |
+
st.session_state.user_info = {"sub": "123", "given_name": "master", "email": "[email protected]"}
|
22 |
+
|
23 |
+
if auth_state:
|
24 |
+
profile_completeness = True # Simulating profile completeness
|
25 |
+
|
26 |
+
if profile_completeness:
|
27 |
+
st.snow()
|
28 |
+
st.success("Enter a chat to the chat input bar and press enter or tap the arrow")
|
29 |
+
st.write(f"# Welcome Back {st.session_state.user_info['given_name']}")
|
30 |
+
st.session_state.Prompt = st.chat_input("Detect Cyber Bullying In conversations")
|
31 |
+
display_previous_chats()
|
32 |
+
|
33 |
+
if st.session_state.Prompt:
|
34 |
+
st.info("TAP ON THE BAR CHART IT'S INTERACTIVE",icon="ℹ️")
|
35 |
+
|
36 |
+
user(st.session_state.Prompt)
|
37 |
+
Respond, Response = thinnk(st.session_state.Prompt)
|
38 |
+
if Respond:
|
39 |
+
data_ = generate_bar_chart(Response)
|
40 |
+
bot_response(Response,data_)
|
41 |
+
else:
|
42 |
+
st.info("Please complete your profile")
|
43 |
+
# Simulated profile completion steps
|
44 |
+
# ...
|
45 |
+
|
46 |
+
# Simulated logout button
|
47 |
+
if not st.session_state.user_info:
|
48 |
+
st.write("# Please login to continue")
|
chating.py
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import streamlit as st
|
3 |
+
import random as rd
|
4 |
+
|
5 |
+
def generate_bar_chart(testing):
|
6 |
+
try:
|
7 |
+
if "1" in testing and "^" in testing and "*" in testing and "@" in testing and "&" in testing: # No chance of not bullying context
|
8 |
+
d = {"Cyberbullying": [rd.randint(75, 100)], "Not cyberbullying": [rd.randint(0, 15)]}
|
9 |
+
data = pd.DataFrame(data=d)
|
10 |
+
return data
|
11 |
+
|
12 |
+
elif "0" in testing and "^" in testing and "*" in testing and "@" in testing and "&" in testing: # No chance of bullying context
|
13 |
+
|
14 |
+
d = {"Cyberbullying": [rd.randint(0, 15)], "Not cyberbullying": [rd.randint(70, 95)]}
|
15 |
+
data = pd.DataFrame(data=d)
|
16 |
+
return data
|
17 |
+
|
18 |
+
elif "0" in testing and "^" in testing and "@" in testing and "&" in testing: # higher no bullying chance than bullying chance but keep it in a 68,32 range
|
19 |
+
|
20 |
+
d = {"Cyberbullying": [rd.randint(12, 28)], "Not cyberbullying": [rd.randint(32, 68)]}
|
21 |
+
data = pd.DataFrame(data=d)
|
22 |
+
return data
|
23 |
+
|
24 |
+
elif "1" in testing and "^" in testing and "@" in testing and "&" in testing: # higher bullying chance than bullying chance but keep it in a 68,32 range
|
25 |
+
d = {"Cyberbullying": [rd.randint(32, 68)], "Not cyberbullying": [rd.randint(10, 28)]}
|
26 |
+
data = pd.DataFrame(data=d)
|
27 |
+
return data
|
28 |
+
|
29 |
+
except TypeError:
|
30 |
+
return None
|
31 |
+
|
32 |
+
# Example usage:
|
33 |
+
# testing_value = st.chat_input("enter a number between 1 and 0")
|
34 |
+
# chart_data = generate_bar_chart(testing_value)
|
35 |
+
|
36 |
+
# if chart_data is not None:
|
37 |
+
# st.bar_chart(chart_data)
|
38 |
+
|
39 |
+
def response_calculator(res):
|
40 |
+
if "1" in res and "^" in res and "*" in res and "@" in res and "&" in res: # No chance of not bullying context
|
41 |
+
response = ["There is almost no way the text here wasn't meant to bully someone","The text wey dey here get wahala, e look like say dem get intention to bully anybody.","E no go hard make person see this text as bully, e dey show say na normal bully dey type.","The person fit get strong mind to bully with this text; e no too dey simple and jejely.","There's a very high probability that the text was meant to bully someone; it appears quite benign.","It's unlikely that the author's intention in this text was not to engage in bullying behavior.","The probability of the text being intended as a form of bullying is extremely high.","It's easy to interpret the text as a means of bullying.","The person wey write am dey carry you for mind ohh.","Make we rise boys for your matter who dey disrespect my boss like this.","How person go disrespect you like this and u will come and show me are you not ashamed.","It's wrong to say such this is the work of a bully.","Hmmm you sef look at the chart. What do you see?","Oga no dey ask some kind questions"]
|
42 |
+
return response[rd.randint(0,13)]
|
43 |
+
|
44 |
+
elif "0" in res and "^" in res and "*" in res and "@" in res and "&" in res: # No chance of bullying context
|
45 |
+
|
46 |
+
response = ["There's an extremely low likelihood that the text here was intended to bully someone.","The text wey dey here no get wahala, e no show like say dem get intention to bully person.","It's quite easy for someone to see this text as anything but a form of bullying; e dey like say dem just dey use style for normal discussion.","The person no fit get mind to bully with this text; e dey simple and jejely.","The probability of the text being intended as a form of bullying is very low; e dey benign.","It's unlikely that the author's intention in this text was to engage in bullying behavior.","The probability of the text being intended as a form of bullying is extremely low; e no fit get any bad intention.","It no fit hard to interpret the text as anything other than a normal conversation; e no get serious likelihood of being bullying.","This text no dey carry signs wey fit mean say dem wan use am bully person; e just dey normal.","The person wey write this text no fit carry bad mind; e no resemble person wey wan bully.","The text no dey carry any serious signs of being intended as a form of bullying.","It no fit be say the text na intentional bully; the intent behind am no dey congruent with such behavior.","Hmmm, if you check the stats well, e be like say person no get mind to throw any kind cyber punch.","Oga, you no dey ask some kind questions wey fit show say you wan provoke person."]
|
47 |
+
return response[rd.randint(0,13)]
|
48 |
+
|
49 |
+
|
50 |
+
elif "0" in res and "^" in res and "@" in res and "&" in res: # higher no bullying chance than bullying chance but keep it in a 68,32 range
|
51 |
+
|
52 |
+
response = ["There's a possibility that the text here was intended to spark interest.","The text wey dey here get some depth; e fit be say dem get intention to engage someone's thoughts.","It might be challenging for someone to interpret this text as anything other than potentially thought-provoking; e dey like say dem just dey use style.","The person fit get mind to generate discussion with this text; e no too dey simple and jejely.","The probability of the text being intended as thought-provoking is quite notable; e no too dey benign at all.","It's possible that the author's intention in this text was to evoke a reaction.","The probability of the text being intended as thought-provoking is not extremely low; e fit carry some tension.","It might be challenging to interpret the text as anything other than a means of sparking interest; e get a serious likelihood.","This text dey carry signs wey fit mean say dem wan add some flavor to am; e no just dey normal.","The person wey write this text fit carry some strong vibes; e resemble person wey wan stimulate some thoughts.","The text dey carry some serious signs of being intended as thought-provoking.","It might be the case that the text is intentionally engaging; the intent behind am dey congruent with such expression.","Hmmm, if you check the stats well, e be like say person get mind to make some bold but insightful statements.","Oga, no dey ask some kind questions wey fit show say you wan start some thoughtful discussion."]
|
53 |
+
return response[rd.randint(0,13)]
|
54 |
+
|
55 |
+
|
56 |
+
elif "1" in res and "^" in res and "@" in res and "&" in res: # higher bullying chance than bullying chance but keep it in a 68,32 range
|
57 |
+
response = ["There's a significant likelihood that the text here was intended to bully someone.","The text wey dey here get serious wahala, e show like say dem get strong intention to bully person.","It fit hard person to see this text as anything but a form of intense bullying; e dey like say dem just dey use style.","The person fit get strong mind to bully with this text; e no too dey simple and jejely.","The probability of the text being intended as a form of bullying is notably high; e no dey benign at all.","It's quite likely that the author's intention in this text was to engage in aggressive behavior and bullying.","The probability of the text being intended as a form of bullying is not extremely low; e fit get some bad and intense intention.","It fit hard to interpret the text as anything other than a means of serious bullying; e get a serious likelihood.","This text dey carry signs wey fit mean say dem wan use am bully person; e no just dey normal.","The person wey write this text fit carry strong bad mind; e resemble person wey wan bully intensely.","The text dey carry some serious signs of being intended as a form of intense bullying.","It fit be say the text na intentional bully; the intent behind am dey congruent with such intense behavior.","Hmmm, if you check the stats well, e be like say person get strong mind to throw some kind cyber punches.","Oga, no dey ask some kind questions wey fit show say you wan provoke person with serious vibes."]
|
58 |
+
return response[rd.randint(0,13)]
|
59 |
+
|
60 |
+
|
61 |
+
if "messages" not in st.session_state:
|
62 |
+
st.session_state.messages = []
|
63 |
+
|
64 |
+
if "message_charts" not in st.session_state:
|
65 |
+
st.session_state.message_charts = []
|
66 |
+
|
67 |
+
def display_previous_chats ():
|
68 |
+
if "messages" not in st.session_state:
|
69 |
+
st.session_state.messages = []
|
70 |
+
for message in st.session_state.messages:
|
71 |
+
with st.chat_message(message["role"]):
|
72 |
+
st.markdown(message["content"])
|
73 |
+
if message["role"] == "assistant":
|
74 |
+
st.bar_chart(message["Chart"])
|
75 |
+
|
76 |
+
|
77 |
+
def user(Prompt):
|
78 |
+
if "messages" not in st.session_state:
|
79 |
+
st.session_state.messages = []
|
80 |
+
user_prompt = st.chat_message("user")
|
81 |
+
user_prompt.write(Prompt)
|
82 |
+
st.session_state.messages.append({"role":"user","content":Prompt,"Chart":None})
|
83 |
+
|
84 |
+
|
85 |
+
|
86 |
+
def bot_response(Prompt,data):
|
87 |
+
if "messages" not in st.session_state:
|
88 |
+
st.session_state.messages = []
|
89 |
+
if "message_charts" not in st.session_state:
|
90 |
+
st.session_state.message_charts = []
|
91 |
+
|
92 |
+
bot_res = st.chat_message("assistant")
|
93 |
+
The_gist = response_calculator(Prompt)
|
94 |
+
|
95 |
+
bot_res.write(The_gist)
|
96 |
+
bot_res.bar_chart(data,use_container_width=True)
|
97 |
+
st.session_state.messages.append({ "role":"assistant", "content":The_gist, "Chart":data })
|
database.py
ADDED
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import mysql.connector
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
def check_if_pk_exists(PK,YourTableName,yourPrimaryKeyColumn):
|
11 |
+
|
12 |
+
|
13 |
+
# Establish a connection
|
14 |
+
db_connection = mysql.connector.connect(
|
15 |
+
host='svc-469e9a44-2c3e-4c14-a4c6-4c9474675828-dml.aws-virginia-6.svc.singlestore.com',
|
16 |
+
|
17 |
+
# In your case your host is local and you are using root assuming you want to deploy the webapp alot will change but start with the db
|
18 |
+
user='admin',
|
19 |
+
password='zxROkpE7ch8vPiU8aGUosQaykRQI4rUc',
|
20 |
+
database='User_profile'
|
21 |
+
)
|
22 |
+
|
23 |
+
|
24 |
+
cursor = db_connection.cursor()
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
select_query = f"SELECT * FROM {YourTableName} WHERE {yourPrimaryKeyColumn} = %s"
|
29 |
+
cursor.execute(select_query, (PK,))
|
30 |
+
existing_row = cursor.fetchone()
|
31 |
+
|
32 |
+
if existing_row:
|
33 |
+
# Commit the changes to the database
|
34 |
+
db_connection.commit()
|
35 |
+
|
36 |
+
# Close the cursor and connection
|
37 |
+
cursor.close()
|
38 |
+
db_connection.close()
|
39 |
+
|
40 |
+
return True
|
41 |
+
else:
|
42 |
+
db_connection.commit()
|
43 |
+
cursor.close()
|
44 |
+
db_connection.close()
|
45 |
+
return False
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
def insert_into_user_reg(UserID,name,email):
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
db_connection = mysql.connector.connect(
|
55 |
+
host='svc-469e9a44-2c3e-4c14-a4c6-4c9474675828-dml.aws-virginia-6.svc.singlestore.com',
|
56 |
+
|
57 |
+
# In your case your host is local and you are using root assuming you want to deploy the webapp alot will change but start with the db
|
58 |
+
user='admin',
|
59 |
+
password='zxROkpE7ch8vPiU8aGUosQaykRQI4rUc',
|
60 |
+
database='User_profile'
|
61 |
+
)
|
62 |
+
|
63 |
+
|
64 |
+
cursor = db_connection.cursor()
|
65 |
+
|
66 |
+
|
67 |
+
# Define your SQL query for insertion
|
68 |
+
insert_query = f"""
|
69 |
+
INSERT INTO Users (UserID, name, email)
|
70 |
+
VALUES (%s, %s, %s)
|
71 |
+
"""
|
72 |
+
|
73 |
+
# Data to be inserted
|
74 |
+
data_to_insert = (f"{UserID}", f"{name}", f"{email}")
|
75 |
+
|
76 |
+
# Execute the query
|
77 |
+
cursor.execute(insert_query, data_to_insert)
|
78 |
+
|
79 |
+
# Commit the changes to the database
|
80 |
+
db_connection.commit()
|
81 |
+
|
82 |
+
# Close the cursor and connection
|
83 |
+
cursor.close()
|
84 |
+
db_connection.close()
|
85 |
+
|
86 |
+
|
87 |
+
def fk_status_profile_completeness(UID):
|
88 |
+
db_connection = mysql.connector.connect(
|
89 |
+
host='svc-469e9a44-2c3e-4c14-a4c6-4c9474675828-dml.aws-virginia-6.svc.singlestore.com',
|
90 |
+
|
91 |
+
# In your case your host is local and you are using root assuming you want to deploy the webapp alot will change but start with the db
|
92 |
+
user='admin',
|
93 |
+
password='zxROkpE7ch8vPiU8aGUosQaykRQI4rUc',
|
94 |
+
database='User_profile'
|
95 |
+
)
|
96 |
+
cursor = db_connection.cursor()
|
97 |
+
|
98 |
+
|
99 |
+
select_query = "SELECT * FROM Ai_personalized_guide_for_users WHERE UserID = %s"
|
100 |
+
cursor.execute(select_query, (UID,))
|
101 |
+
existing_row = cursor.fetchone()
|
102 |
+
if existing_row:
|
103 |
+
db_connection.commit()
|
104 |
+
cursor.close()
|
105 |
+
db_connection.close()
|
106 |
+
return True # key exists
|
107 |
+
else:
|
108 |
+
db_connection.commit()
|
109 |
+
cursor.close()
|
110 |
+
db_connection.close()
|
111 |
+
return False # key doesn't exist
|
112 |
+
|
113 |
+
|
114 |
+
|
115 |
+
def insert_into_ai_personalized_guide_for_users(UserID,reading_speed,level_of_understanding,diction):
|
116 |
+
|
117 |
+
|
118 |
+
|
119 |
+
db_connection = mysql.connector.connect(
|
120 |
+
host='svc-469e9a44-2c3e-4c14-a4c6-4c9474675828-dml.aws-virginia-6.svc.singlestore.com',
|
121 |
+
|
122 |
+
# In your case your host is local and you are using root assuming you want to deploy the webapp alot will change but start with the db
|
123 |
+
user='admin',
|
124 |
+
password='zxROkpE7ch8vPiU8aGUosQaykRQI4rUc',
|
125 |
+
database='User_profile'
|
126 |
+
)
|
127 |
+
|
128 |
+
|
129 |
+
cursor = db_connection.cursor()
|
130 |
+
|
131 |
+
|
132 |
+
# Define your SQL query for insertion
|
133 |
+
insert_query = f"""
|
134 |
+
INSERT INTO Ai_personalized_guide_for_users (UserID, reading_speed, level_of_understanding,diction)
|
135 |
+
VALUES (%s, %s, %s,%s)
|
136 |
+
"""
|
137 |
+
|
138 |
+
# Data to be inserted
|
139 |
+
data_to_insert = (f"{UserID}", f"{reading_speed}", f"{level_of_understanding}",f"{diction}")
|
140 |
+
|
141 |
+
# Execute the query
|
142 |
+
cursor.execute(insert_query, data_to_insert)
|
143 |
+
|
144 |
+
# Commit the changes to the database
|
145 |
+
db_connection.commit()
|
146 |
+
|
147 |
+
# Close the cursor and connection
|
148 |
+
cursor.close()
|
149 |
+
db_connection.close()
|
requirements.txt
ADDED
Binary file (172 Bytes). View file
|
|
variables.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
from openai import OpenAI
|
4 |
+
|
5 |
+
|
6 |
+
load_dotenv()
|
7 |
+
client = OpenAI()
|
8 |
+
|
9 |
+
|
10 |
+
def trial():
|
11 |
+
user_input = input("enter Prompt")
|
12 |
+
done_thinking,response =thinnk(user_input)
|
13 |
+
if done_thinking:
|
14 |
+
print(response)
|
15 |
+
|
16 |
+
else: print("someothing went wrong")
|
17 |
+
|
18 |
+
|
19 |
+
def thinnk(user_):
|
20 |
+
response = client.chat.completions.create(
|
21 |
+
model="ft:gpt-3.5-turbo-1106:group-c::8YTKwLjB",
|
22 |
+
messages=[
|
23 |
+
{"role": "system", "content": "You are a school guidance counsellor on the lookout for chats that hint of cyberbullying in a WhatsApp group chat."},
|
24 |
+
{"role": "user", "content": user_}
|
25 |
+
]
|
26 |
+
)
|
27 |
+
ai_response = response.choices[0].message.content
|
28 |
+
return True , ai_response
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
clientId = 'YexToZlUgbRsHRjbzy8yckhAoegwQEcX'
|
50 |
+
domainName = 'dev-r7cupi8h76qk3w31.us.auth0.com'
|
51 |
+
|
52 |
+
text_for_tab_1 ="""
|
53 |
+
Select a value to help your bot know
|
54 |
+
how fast you read, speed increases from 1
|
55 |
+
for very slow readers up to 5 for very fast reader"""
|
56 |
+
|
57 |
+
text_for_tab_2 ="""Opt for 1 if you typically require additional time when learning
|
58 |
+
new things, or select 5 if acquiring new knowledge comes effortlessly
|
59 |
+
to you.
|
60 |
+
|
61 |
+
"""
|
62 |
+
text_for_tab_3 ="""
|
63 |
+
Please indicate a value that
|
64 |
+
reflects your current proficiency in English
|
65 |
+
for your bot's understanding.
|
66 |
+
Choose 1 if your vocabulary is fundamental,
|
67 |
+
or select 5 if you appreciate
|
68 |
+
using extensive and sophisticated language."""
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
def run_once():
|
73 |
+
if "user_info" not in st.session_state:
|
74 |
+
st.session_state.user_info = False
|
75 |
+
|
76 |
+
|
77 |
+
if "signed_in" not in st.session_state:
|
78 |
+
st.session_state.signed_in = False
|
79 |
+
|
80 |
+
if "t2" and "t1" and "t3" not in st.session_state:
|
81 |
+
st.session_state.t1 = False
|
82 |
+
st.session_state.t2 = False
|
83 |
+
st.session_state.t3 = False
|
84 |
+
|
85 |
+
if "Prompt" not in st.session_state:
|
86 |
+
st.session_state.Prompt = False
|
87 |
+
|
88 |
+
if "messages" not in st.session_state:
|
89 |
+
st.session_state.messages = []
|
90 |
+
|
91 |
+
|