Skip to content

Commit d714377

Browse files
committed
update some exception
1 parent b180fd3 commit d714377

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

background.png

719 Bytes
Loading

edit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def run(self):
4747
self.signal.emit(text)
4848
'''
4949

50-
text = getPredictText(self.text.replace('\n', ''), length=50)
50+
text = getPredictText(self.text.replace('\n', ''), length=500)
5151
self.signal.emit(text)
5252

5353

generation.py

+4
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ def getPredictText(text: str, length: int = 200) -> str:
2424
# 使用tokenizer将生成的id转为文本
2525
generatedText = tokenizer.convert_ids_to_string(ids)
2626
return generatedText
27+
28+
29+
getPredictText('开始预测模型会先初始化一下, 抵消掉这个时间')
30+

main.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ def run(self):
4545
screensize = (800, 600)
4646
videoClips = []
4747
for i, section in enumerate(self.sections):
48+
4849
imgPath, text = section[0], section[1]
50+
if len(text) >= 1:
51+
mark = text[-1]
52+
if mark == '$':
53+
text = text[:-1]
4954
text = text.split(r'\\')
5055
text = '\\'.join([x.replace(r'\n', '\n') for x in text])
5156
text = text.strip().split('\n')
@@ -64,9 +69,11 @@ def run(self):
6469
clip = ImageClip(imgPath)
6570

6671
# 设置一下图片/gif大小
67-
width, height = clip.size
68-
width, height = resizeImg(width, height)
69-
clip = clip.resize((width, height))
72+
if mark != '$':
73+
width, height = clip.size
74+
width, height = resizeImg(width, height)
75+
clip = clip.resize((width, height))
76+
7077

7178
# 考虑到每张表情包可能对应多句字幕
7279
for txt in text:

utils.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ def getBaiduImgPath(text: str) -> [Iterable, None]:
134134
res = requests.get(url, headers=headers, verify=False)
135135
if res.status_code != 200:
136136
return None
137-
jsonData = json.loads(res.text)
137+
try:
138+
jsonData = json.loads(res.text)
139+
except:
140+
return None
138141
if 'data' not in jsonData:
139142
return None
140143
data = jsonData['data']
@@ -182,7 +185,10 @@ def getDoutulaImgPath(text: str) -> [Iterable, None]:
182185
randomPics = soup.find_all('a', attrs={'class': 'col-xs-6 col-md-2'})
183186
for pic in randomPics:
184187
imgUrl = pic.find('img', attrs={'referrerpolicy': 'no-referrer'})['data-original']
185-
res = requests.get(imgUrl)
188+
try:
189+
res = requests.get(imgUrl)
190+
except:
191+
return None
186192
if res.status_code != 200:
187193
continue
188194
path = os.path.join('tmp', imgUrl[imgUrl.rfind('/') + 1:])

0 commit comments

Comments
 (0)