Spaces:
Runtime error
Runtime error
Refactoring for validation
Browse files
app.py
CHANGED
|
@@ -48,29 +48,34 @@ def format_results(results: List[Tuple[str, str]]) -> str:
|
|
| 48 |
output = output.strip()
|
| 49 |
return output
|
| 50 |
|
| 51 |
-
def
|
| 52 |
-
if not tags:
|
| 53 |
raise gr.Error('Validation error. It is necessary to set at least one tag')
|
|
|
|
|
|
|
| 54 |
if len(tags) > max_tags_count:
|
| 55 |
raise gr.Error(f'Validation error. The maximum allowed number of tags is {max_tags_count}.')
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
def
|
| 58 |
-
if not questions:
|
| 59 |
raise gr.Error('Validation error. It is necessary to ask at least one question')
|
|
|
|
|
|
|
| 60 |
if len(questions) > max_questions_count:
|
| 61 |
raise gr.Error(f'Validation error. The maximum allowed number of questions is {max_questions_count}.')
|
|
|
|
|
|
|
| 62 |
|
| 63 |
def find_answers(tags: str, questions: str, progress=gr.Progress()) -> str:
|
| 64 |
-
tags = tags
|
| 65 |
-
questions = questions
|
| 66 |
|
| 67 |
print(f'New attempt to get answers. Got {len(tags)} tags and {len(questions)} questions')
|
| 68 |
print(f'Tags: {tags}')
|
| 69 |
print(f'Questions: {questions}')
|
| 70 |
|
| 71 |
-
validate_tags(tags)
|
| 72 |
-
validate_questions(questions)
|
| 73 |
-
|
| 74 |
tags_str = ''.join([f'[{tag}]' for tag in tags])
|
| 75 |
|
| 76 |
results = []
|
|
|
|
| 48 |
output = output.strip()
|
| 49 |
return output
|
| 50 |
|
| 51 |
+
def validate_and_get_tags(tags: str) -> List[str]:
|
| 52 |
+
if not tags.strip():
|
| 53 |
raise gr.Error('Validation error. It is necessary to set at least one tag')
|
| 54 |
+
|
| 55 |
+
tags = tags.split('\n')
|
| 56 |
if len(tags) > max_tags_count:
|
| 57 |
raise gr.Error(f'Validation error. The maximum allowed number of tags is {max_tags_count}.')
|
| 58 |
+
|
| 59 |
+
return tags
|
| 60 |
|
| 61 |
+
def validate_and_get_questions(questions: str) -> List[str]:
|
| 62 |
+
if not questions.strip():
|
| 63 |
raise gr.Error('Validation error. It is necessary to ask at least one question')
|
| 64 |
+
|
| 65 |
+
questions = questions.split('\n')
|
| 66 |
if len(questions) > max_questions_count:
|
| 67 |
raise gr.Error(f'Validation error. The maximum allowed number of questions is {max_questions_count}.')
|
| 68 |
+
|
| 69 |
+
return questions
|
| 70 |
|
| 71 |
def find_answers(tags: str, questions: str, progress=gr.Progress()) -> str:
|
| 72 |
+
tags = validate_and_get_tags(tags)
|
| 73 |
+
questions = validate_and_get_questions(questions)
|
| 74 |
|
| 75 |
print(f'New attempt to get answers. Got {len(tags)} tags and {len(questions)} questions')
|
| 76 |
print(f'Tags: {tags}')
|
| 77 |
print(f'Questions: {questions}')
|
| 78 |
|
|
|
|
|
|
|
|
|
|
| 79 |
tags_str = ''.join([f'[{tag}]' for tag in tags])
|
| 80 |
|
| 81 |
results = []
|