Update app.py
Browse files
app.py
CHANGED
|
@@ -28,18 +28,18 @@ task_results = {}
|
|
| 28 |
def index():
|
| 29 |
return 'Hello'
|
| 30 |
|
| 31 |
-
def process_analysis(task_id, text, model_name,
|
| 32 |
print(f"Processing task: {task_id}")
|
| 33 |
|
| 34 |
# Validate data
|
| 35 |
print('Validate data')
|
| 36 |
-
answer = validate_data(text, model_name
|
| 37 |
if answer != '':
|
| 38 |
task_results[task_id] = {'status': 'error', 'error': answer}
|
| 39 |
return
|
| 40 |
|
| 41 |
-
topic = check_topic(topic)
|
| 42 |
-
hcRelativeToThreshold, hc, df_sentences = detect_human_text(model_name,
|
| 43 |
|
| 44 |
sentences = [
|
| 45 |
{
|
|
@@ -67,13 +67,14 @@ def check_text():
|
|
| 67 |
data = request.get_json()
|
| 68 |
text = data.get('text')
|
| 69 |
model_name = data.get('model')
|
| 70 |
-
topic = data.get('topic')
|
|
|
|
| 71 |
|
| 72 |
# Generate a unique taskId
|
| 73 |
task_id = str(uuid.uuid4())
|
| 74 |
|
| 75 |
# Start processing in a separate thread
|
| 76 |
-
thread = threading.Thread(target=process_analysis, args=(task_id, text, model_name,
|
| 77 |
thread.start()
|
| 78 |
|
| 79 |
# Return taskId immediately
|
|
@@ -91,21 +92,21 @@ def get_results():
|
|
| 91 |
|
| 92 |
return jsonify(task_results.pop(task_id)), 200
|
| 93 |
|
| 94 |
-
def validate_data(text, model_name, topic):
|
| 95 |
if text is None or text == '':
|
| 96 |
return 'Text is missing'
|
| 97 |
|
| 98 |
if model_name is None or model_name == '':
|
| 99 |
return 'Model name is missing'
|
| 100 |
|
| 101 |
-
if topic is None or topic == '':
|
| 102 |
-
|
| 103 |
|
| 104 |
if model_name not in ['GPT2XL', 'PHI2']:
|
| 105 |
return f'Model {model_name} not supported'
|
| 106 |
|
| 107 |
-
if check_topic(topic) == None:
|
| 108 |
-
|
| 109 |
|
| 110 |
return ''
|
| 111 |
|
|
|
|
| 28 |
def index():
|
| 29 |
return 'Hello'
|
| 30 |
|
| 31 |
+
def process_analysis(task_id, text, model_name, threshold):
|
| 32 |
print(f"Processing task: {task_id}")
|
| 33 |
|
| 34 |
# Validate data
|
| 35 |
print('Validate data')
|
| 36 |
+
answer = validate_data(text, model_name)
|
| 37 |
if answer != '':
|
| 38 |
task_results[task_id] = {'status': 'error', 'error': answer}
|
| 39 |
return
|
| 40 |
|
| 41 |
+
# topic = check_topic(topic)
|
| 42 |
+
hcRelativeToThreshold, hc, df_sentences = detect_human_text(model_name, threshold, text)
|
| 43 |
|
| 44 |
sentences = [
|
| 45 |
{
|
|
|
|
| 67 |
data = request.get_json()
|
| 68 |
text = data.get('text')
|
| 69 |
model_name = data.get('model')
|
| 70 |
+
# topic = data.get('topic')
|
| 71 |
+
threshold = data.get('threshold')
|
| 72 |
|
| 73 |
# Generate a unique taskId
|
| 74 |
task_id = str(uuid.uuid4())
|
| 75 |
|
| 76 |
# Start processing in a separate thread
|
| 77 |
+
thread = threading.Thread(target=process_analysis, args=(task_id, text, model_name, threshold))
|
| 78 |
thread.start()
|
| 79 |
|
| 80 |
# Return taskId immediately
|
|
|
|
| 92 |
|
| 93 |
return jsonify(task_results.pop(task_id)), 200
|
| 94 |
|
| 95 |
+
def validate_data(text, model_name, topic=""):
|
| 96 |
if text is None or text == '':
|
| 97 |
return 'Text is missing'
|
| 98 |
|
| 99 |
if model_name is None or model_name == '':
|
| 100 |
return 'Model name is missing'
|
| 101 |
|
| 102 |
+
# if topic is None or topic == '':
|
| 103 |
+
# return 'Topic is missing'
|
| 104 |
|
| 105 |
if model_name not in ['GPT2XL', 'PHI2']:
|
| 106 |
return f'Model {model_name} not supported'
|
| 107 |
|
| 108 |
+
# if check_topic(topic) == None:
|
| 109 |
+
# return f'Topic {topic} not supported'
|
| 110 |
|
| 111 |
return ''
|
| 112 |
|