Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import numpy as np
|
2 |
import os
|
3 |
import re
|
|
|
4 |
from io import BytesIO
|
5 |
import datetime
|
6 |
import time
|
@@ -60,11 +61,23 @@ class Reviewer:
|
|
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, '
|
64 |
return output_text, response.usage.total_tokens
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
def insert_sentence(text, sentence, interval):
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
new_words = []
|
69 |
count = 0
|
70 |
|
@@ -75,7 +88,7 @@ class Reviewer:
|
|
75 |
if count % interval == 0:
|
76 |
new_words.append(sentence)
|
77 |
|
78 |
-
return
|
79 |
|
80 |
|
81 |
|
|
|
1 |
import numpy as np
|
2 |
import os
|
3 |
import re
|
4 |
+
import jieba
|
5 |
from io import BytesIO
|
6 |
import datetime
|
7 |
import time
|
|
|
61 |
print("completion_token_used:", response.usage.completion_tokens)
|
62 |
print("total_token_used:", response.usage.total_tokens)
|
63 |
print("response_time:", response.response_ms/1000.0, 's')
|
64 |
+
output_text = insert_sentence(result, '**Generated by ChatGPT, no copying allowed!**', 10)
|
65 |
return output_text, response.usage.total_tokens
|
66 |
|
67 |
+
def contains_chinese(text):
|
68 |
+
for ch in text:
|
69 |
+
if u'\u4e00' <= ch <= u'\u9fff':
|
70 |
+
return True
|
71 |
+
return False
|
72 |
+
|
73 |
def insert_sentence(text, sentence, interval):
|
74 |
+
if contains_chinese(text):
|
75 |
+
words = list(jieba.cut(text))
|
76 |
+
separator = ''
|
77 |
+
else:
|
78 |
+
words = text.split()
|
79 |
+
separator = ' '
|
80 |
+
|
81 |
new_words = []
|
82 |
count = 0
|
83 |
|
|
|
88 |
if count % interval == 0:
|
89 |
new_words.append(sentence)
|
90 |
|
91 |
+
return separator.join(new_words)
|
92 |
|
93 |
|
94 |
|