Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,7 +40,7 @@ class Reviewer:
|
|
| 40 |
review_prompt_token = 1000
|
| 41 |
text_token = len(self.encoding.encode(text))
|
| 42 |
input_text_index = int(len(text)*(self.max_token_num-review_prompt_token)/(text_token+1))
|
| 43 |
-
input_text = "This is the paper for your review:" + text[:input_text_index]
|
| 44 |
messages=[
|
| 45 |
{"role": "system", "content": "You are a professional reviewer. Now I will give you a paper. You need to give a complete review opinion according to the following requirements and format:"+ self.review_format +" Must be output in {}.".format(self.language)},
|
| 46 |
{"role": "user", "content": input_text},
|
|
@@ -59,9 +59,26 @@ class Reviewer:
|
|
| 59 |
print("prompt_token_used:", response.usage.prompt_tokens)
|
| 60 |
print("completion_token_used:", response.usage.completion_tokens)
|
| 61 |
print("total_token_used:", response.usage.total_tokens)
|
| 62 |
-
print("response_time:", response.response_ms/1000.0, 's')
|
|
|
|
| 63 |
return result, response.usage.total_tokens
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
def extract_chapter(self, pdf_path):
|
| 66 |
file_object = BytesIO(pdf_path)
|
| 67 |
pdf_reader = PyPDF2.PdfReader(file_object)
|
|
|
|
| 40 |
review_prompt_token = 1000
|
| 41 |
text_token = len(self.encoding.encode(text))
|
| 42 |
input_text_index = int(len(text)*(self.max_token_num-review_prompt_token)/(text_token+1))
|
| 43 |
+
input_text = "This is the paper for your review:" + text[:input_text_index] "(This text is generated by ChatGPT for reference only, strain to copy!)"
|
| 44 |
messages=[
|
| 45 |
{"role": "system", "content": "You are a professional reviewer. Now I will give you a paper. You need to give a complete review opinion according to the following requirements and format:"+ self.review_format +" Must be output in {}.".format(self.language)},
|
| 46 |
{"role": "user", "content": input_text},
|
|
|
|
| 59 |
print("prompt_token_used:", response.usage.prompt_tokens)
|
| 60 |
print("completion_token_used:", response.usage.completion_tokens)
|
| 61 |
print("total_token_used:", response.usage.total_tokens)
|
| 62 |
+
print("response_time:", response.response_ms/1000.0, 's')
|
| 63 |
+
output_text = insert_sentence(result, '("Generated by ChatGPT, no copying allowed!)', 10)
|
| 64 |
return result, response.usage.total_tokens
|
| 65 |
|
| 66 |
+
def insert_sentence(text, sentence, interval):
|
| 67 |
+
words = text.split()
|
| 68 |
+
new_words = []
|
| 69 |
+
count = 0
|
| 70 |
+
|
| 71 |
+
for word in words:
|
| 72 |
+
new_words.append(word)
|
| 73 |
+
count += 1
|
| 74 |
+
|
| 75 |
+
if count % interval == 0:
|
| 76 |
+
new_words.append(sentence)
|
| 77 |
+
|
| 78 |
+
return ' '.join(new_words)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
def extract_chapter(self, pdf_path):
|
| 83 |
file_object = BytesIO(pdf_path)
|
| 84 |
pdf_reader = PyPDF2.PdfReader(file_object)
|