Kashtan/Detect_Edits_in_AI-Generated_Text
0
1#https://www.freecodecamp.org/news/how-to-setup-virtual-environments-in-python/2#https://www.youtube.com/watch?v=qbLc5a9jdXo&ab_channel=CalebCurry3#https://stackoverflow.com/questions/26368306/export-is-not-recognized-as-an-internal-or-external-command4#python3 -m venv .venv5#source .venv/bin/activate6#7#pip freeze > requirements.txt8#$env:FLASK_APP="application.py" #set FLASK_APP=application.py # export FLASK_APP=application.py 9#set FLASK_ENV=development #export FLASK_ENV=production10#flask run #flask run --host=0.0.0.011 12#pip install torchvision13 14from flask import Flask, request, jsonify15from flask_cors import CORS16import pandas17from human_text_detect import detect_human_text18 19app = Flask(__name__)20CORS(app)21 22@app.route('/')23def index():24 return 'Hello'25 26@app.route('/detectHumanInAIText/checkText', methods=['POST'])27def check_text():28 29 # Get data30 print('Get data')31 data = request.get_json()32 text = data.get('text')33 model_name = data.get('model')34 topic = data.get('topic')35 36 # Validate data37 print('Validate data')38 answer = validate_data(text, model_name, topic)39 if answer != '':40 return jsonify({'answer': answer}), 40041 42 topic = check_topic(topic)43 answer = detect_human_text(model_name, topic, text)44 45 return jsonify({'answer': answer})46 47def validate_data(text, model_name, topic):48 if text is None or text == '':49 return 'Text is missing'50 51 if model_name is None or model_name == '':52 return 'Model name is missing'53 54 if topic is None or topic == '':55 return 'Topic is missing'56 57 if model_name not in ['GPT2XL', 'PHI2']:58 return f'Model {model_name} not supported'59 60 if topic not in ['Characters', 'Locations', 'Nature', 'Video games', 'Series', 'Movies', 'War']:61 return f'Topic {topic} not supported'62 63 return ''64 65def check_topic(topic):66 topic_dict = {67 'Characters': 'characters',68 'Locations': 'locations',69 'Nature': 'nature',70 'Video games': 'video_games_series_movies',71 'Series': 'video_games_series_movies',72 'Movies': 'video_games_series_movies',73 'War': 'war'74 }75 76 return topic_dict[topic]