idkash1 commited on
Commit
6cca969
·
verified ·
1 Parent(s): 07cb8d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
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, 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,14 +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
  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,21 +92,21 @@ def get_results():
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
 
 
28
  def index():
29
  return 'Hello'
30
 
31
+ def process_analysis(task_id, text, model_name, topic, threshold):
32
  print(f"Processing task: {task_id}")
33
 
34
  # Validate data
35
  print('Validate data')
36
+ answer = validate_data(text, model_name, topic)
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, topic, 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, topic, 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