imseldrith commited on
Commit
c17dbac
·
1 Parent(s): 6365946

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -37
app.py CHANGED
@@ -1,44 +1,26 @@
1
- import nltk
2
- import re
3
- nltk.download('punkt')
4
- from nltk.tokenize import sent_tokenize, word_tokenize
5
- from nltk.corpus import stopwords
6
- from nltk.probability import FreqDist
7
  from flask import Flask, request, render_template
 
 
8
 
9
  app = Flask(__name__)
10
 
11
- nltk.download('stopwords')
12
- stop_words = set(stopwords.words("english"))
13
-
14
- @app.route('/')
15
  def index():
16
- return render_template('index.html')
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- @app.route('/detect', methods=['POST'])
19
- def detect_ai():
20
- content = request.form['content']
21
- # Tokenize the content into sentences
22
- sentences = sent_tokenize(content)
23
- # Check for the number of sentences
24
- if len(sentences) < 3:
25
- return "This content is likely generated by AI"
26
- # Tokenize each sentence into words
27
- words = [word_tokenize(sentence) for sentence in sentences]
28
- # Remove stop words and special characters
29
- words = [[word.lower() for word in sentence if word.isalpha() and word.lower() not in stop_words] for sentence in words]
30
- # Create a frequency distribution of the words
31
- fdist = FreqDist([word for sentence in words for word in sentence])
32
- # Check the average frequency of words in the content
33
- avg_freq = sum(fdist.values())/len(fdist)
34
- if avg_freq < 2:
35
- return "This content is likely generated by AI"
36
- # Check for the use of common regex patterns
37
- regex_patterns = [r'\b\w{5,}\b', r'\b\d{1,}\b', r'\b\w{5,}\b \b\w{5,}\b']
38
- for pattern in regex_patterns:
39
- if re.search(pattern, content):
40
- return "This content is likely generated by AI"
41
- return "This content is likely not generated by AI"
42
 
43
- if __name__ == '__main__':
44
- app.run(host='0.0.0.0',port=7860)
 
 
 
 
 
 
 
1
  from flask import Flask, request, render_template
2
+ import transformers
3
+ import parrot
4
 
5
  app = Flask(__name__)
6
 
7
+ @app.route("/", methods=["GET", "POST"])
 
 
 
8
  def index():
9
+ if request.method == "POST":
10
+ text = request.form["text"]
11
+ library = request.form["library"]
12
+
13
+ if library == "transformers":
14
+ model = transformers.AutoModelWithLMHead.from_pretrained("gpt2")
15
+ paraphrased_text = transformers.generate(model, text)
16
+ elif library == "parrot":
17
+ paraphrased_text = parrot.paraphrase(text)
18
+ else:
19
+ return "Error: Invalid library selected"
20
+
21
+ return render_template("index.html", original_text=text, paraphrased_text=paraphrased_text)
22
 
23
+ return render_template("index.html")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ if __name__ == "__main__":
26
+ app.run(host="0.0.0.0",port=7860)