ayoni02 commited on
Commit
d9fdfda
·
1 Parent(s): 17297b3

first commit

Browse files
Files changed (4) hide show
  1. ap.py +35 -0
  2. app.py +14 -0
  3. main.py +56 -0
  4. requirements.txt +3 -0
ap.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import modules
2
+ from flask import Flask, render_template, session, redirect, url_for
3
+ from flask_wtf import FlaskForm
4
+ from wtforms import SubmitField, TextAreaField
5
+
6
+ import env_variable
7
+ import main
8
+
9
+ app = Flask(__name__)
10
+
11
+ app.config['SECRET_KEY'] = env_variable.app_security_key
12
+
13
+ class TextForm(FlaskForm):
14
+ text = TextAreaField('Text')
15
+ submit = SubmitField('Send')
16
+
17
+
18
+ @app.route('/', methods=['GET', 'POST'])
19
+ def index():
20
+ form = TextForm()
21
+ if form.validate_on_submit(): # Check if form is submitted
22
+ session['text'] = form.text.data
23
+ return redirect(url_for("moderator"))
24
+ return render_template('home.html', form=form)
25
+
26
+
27
+ @app.route('/moderator')
28
+ def moderator():
29
+ text = session['text']
30
+ result = main.content_moderator(text)
31
+ return render_template('moderator.html', result=result)
32
+
33
+
34
+ if __name__ == '__main__':
35
+ app.run(debug=True)
app.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import main
3
+
4
+
5
+ def main():
6
+ text = st.text_input("Enter the text to classify: ")
7
+ if text:
8
+ results = main.content_moderator(text)
9
+ st.write(results)
10
+ else:
11
+ st.write("Please enter some text to classify")
12
+ st.write("Waiting for input...")
13
+
14
+ main()
main.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import requests as re
3
+
4
+ labels = ['toxic', 'racist', 'gender bias', 'religious bias', 'aggressive',
5
+ 'personal attacks', 'hate speech', 'offensive language']
6
+
7
+ # model chosen is fbbart
8
+ model = pipeline("zero-shot-classification",
9
+ model="facebook/bart-large-mnli")
10
+
11
+
12
+ def zero_shot_classifier(text, model=model, labels=labels):
13
+ text = text
14
+ prediction = model(text, labels, multi_label=True)
15
+ if prediction["scores"][0] < 0.75:
16
+ return False
17
+ else:
18
+ return str(prediction["labels"][0])
19
+
20
+
21
+ # catch darkweb links
22
+ def dark_web_links(text):
23
+ # Regular expression pattern to match common dark web link formats
24
+ dark_web_pattern = r"(https?://)?[a-z0-9]+\.onion(/[a-zA-Z0-9]*)*"
25
+
26
+ # Search for dark web links in the text
27
+ matches = re.findall(dark_web_pattern, text)
28
+
29
+ if matches:
30
+ return True
31
+ else:
32
+ return False
33
+
34
+
35
+ # catch adult content links
36
+ def adult_content_sites(text):
37
+ # Regular expression pattern to match common adult content websites
38
+ adult_content_pattern = r"(https?://)?(?:www\.)?(pornhub\.com|xnxx\.com|youporn\.com|redtube\.com|etc)\b"
39
+
40
+ # Search for adult content sites in the text
41
+ matches = re.findall(adult_content_pattern, text)
42
+
43
+ # If any matches are found, flag them
44
+ if matches:
45
+ return True
46
+ else:
47
+ return False
48
+
49
+
50
+ def content_moderator(text, labels=labels, model=model, classifier=zero_shot_classifier, dkweb=dark_web_links, adult=adult_content_sites):
51
+ if dkweb(text):
52
+ return 'Darkweb link'
53
+ elif adult(text):
54
+ return 'Adult content site'
55
+ elif classifier(text):
56
+ return 'Flagged content'
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ streamlit