Spaces:
Runtime error
Runtime error
Added types to methods
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from gradio.components import Textbox
|
|
3 |
import requests
|
4 |
import json
|
5 |
import time
|
|
|
6 |
|
7 |
MAX_QUESTIONS_COUNT = 25
|
8 |
MAX_TAGS_COUNT = 5
|
@@ -10,7 +11,7 @@ MAX_ATTEMPS = 3
|
|
10 |
WAIT_TIME = 3
|
11 |
CHATGPT_URL = 'https://free.churchless.tech/v1/chat/completions'
|
12 |
|
13 |
-
def get_answer(question):
|
14 |
headers = {
|
15 |
'Content-Type': 'application/json; charset=utf-8'
|
16 |
}
|
@@ -21,7 +22,7 @@ def get_answer(question):
|
|
21 |
'content': question
|
22 |
}]
|
23 |
}
|
24 |
-
|
25 |
try:
|
26 |
response = requests.post(CHATGPT_URL, headers=headers, data=json.dumps(payload))
|
27 |
response.raise_for_status()
|
@@ -35,7 +36,7 @@ def get_answer(question):
|
|
35 |
'status': False
|
36 |
}
|
37 |
|
38 |
-
def format_results(results):
|
39 |
output = ""
|
40 |
for i, (question, answer) in enumerate(results):
|
41 |
output += f'Question №{i+1}: {question}\n'
|
@@ -45,19 +46,19 @@ def format_results(results):
|
|
45 |
output = output.strip()
|
46 |
return output
|
47 |
|
48 |
-
def validate_tags(tags):
|
49 |
if not tags:
|
50 |
raise gr.Error('Validation error. It is necessary to set at least one tag')
|
51 |
if len(tags) > MAX_TAGS_COUNT:
|
52 |
raise gr.Error(f'Validation error. The maximum allowed number of tags is {MAX_TAGS_COUNT}.')
|
53 |
|
54 |
-
def validate_questions(questions):
|
55 |
if not questions:
|
56 |
raise gr.Error('Validation error. It is necessary to ask at least one question')
|
57 |
if len(questions) > MAX_QUESTIONS_COUNT:
|
58 |
raise gr.Error(f'Validation error. The maximum allowed number of questions is {MAX_QUESTIONS_COUNT}.')
|
59 |
|
60 |
-
def find_answers(tags, questions):
|
61 |
tags = tags.split('\n')
|
62 |
questions = questions.split('\n')
|
63 |
|
|
|
3 |
import requests
|
4 |
import json
|
5 |
import time
|
6 |
+
from typing import List, Tuple, Dict, Any
|
7 |
|
8 |
MAX_QUESTIONS_COUNT = 25
|
9 |
MAX_TAGS_COUNT = 5
|
|
|
11 |
WAIT_TIME = 3
|
12 |
CHATGPT_URL = 'https://free.churchless.tech/v1/chat/completions'
|
13 |
|
14 |
+
def get_answer(question: str) -> Dict[str, Any]:
|
15 |
headers = {
|
16 |
'Content-Type': 'application/json; charset=utf-8'
|
17 |
}
|
|
|
22 |
'content': question
|
23 |
}]
|
24 |
}
|
25 |
+
|
26 |
try:
|
27 |
response = requests.post(CHATGPT_URL, headers=headers, data=json.dumps(payload))
|
28 |
response.raise_for_status()
|
|
|
36 |
'status': False
|
37 |
}
|
38 |
|
39 |
+
def format_results(results: List[Tuple[str, str]]) -> str:
|
40 |
output = ""
|
41 |
for i, (question, answer) in enumerate(results):
|
42 |
output += f'Question №{i+1}: {question}\n'
|
|
|
46 |
output = output.strip()
|
47 |
return output
|
48 |
|
49 |
+
def validate_tags(tags: str) -> None:
|
50 |
if not tags:
|
51 |
raise gr.Error('Validation error. It is necessary to set at least one tag')
|
52 |
if len(tags) > MAX_TAGS_COUNT:
|
53 |
raise gr.Error(f'Validation error. The maximum allowed number of tags is {MAX_TAGS_COUNT}.')
|
54 |
|
55 |
+
def validate_questions(questions: str) -> None:
|
56 |
if not questions:
|
57 |
raise gr.Error('Validation error. It is necessary to ask at least one question')
|
58 |
if len(questions) > MAX_QUESTIONS_COUNT:
|
59 |
raise gr.Error(f'Validation error. The maximum allowed number of questions is {MAX_QUESTIONS_COUNT}.')
|
60 |
|
61 |
+
def find_answers(tags: str, questions: str) -> str:
|
62 |
tags = tags.split('\n')
|
63 |
questions = questions.split('\n')
|
64 |
|