rogerxavier commited on
Commit
cc23ba9
1 Parent(s): c2df0d7

Update 3mergeDialogToVideo.py

Browse files
Files changed (1) hide show
  1. 3mergeDialogToVideo.py +32 -37
3mergeDialogToVideo.py CHANGED
@@ -33,6 +33,29 @@ print("azure key是",azure_speech_key)
33
  print("azure_service_region是",azure_service_region)
34
  print("my_openai_key",my_openai_key)
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  #通过去水印完整漫画图片->获取相应的对话框图片->获取对话框文字->返回对话框文字
37
  def get_image_copywrite(image_path:"图片路径(包含后缀)",dialog_cut_path:"对话框切割路径")->"返回漫画关联对话框识别后得到的文案str(原文即可),也可能是none":
38
  def extract_chinese(text:str)->str:
@@ -204,31 +227,20 @@ def sort_dialog_list(sorted_indices:list,related_groups:list,sorted_coordinates)
204
  return filtered_data
205
 
206
 
207
- def get_sorted_dialog_text(image_path:"包含后缀的文件路径")->"返回排序后的text list(一列或者几列话,反正是一个框的内容,几句不清楚,一个框的list当一次文案就行) 或者失败请求返回none":
 
 
 
 
 
 
208
  image_bytes = open(image_path, 'rb')
209
- # headers = {
210
- # 'authority': 'rogerxavier-fastapi-t5-magi.hf.space',
211
- # 'scheme': 'https',
212
- # 'Accept': '*/*',
213
- # 'Accept-Encoding': 'gzip, deflate, br, zstd',
214
- # 'Accept-Language': 'zh-CN,zh;q=0.9',
215
- # 'Cookie': 'spaces-jwt=eyJhbGciOiJFZERTQSJ9.eyJyZWFkIjp0cnVlLCJwZXJtaXNzaW9ucyI6eyJyZXBvLmNvbnRlbnQucmVhZCI6dHJ1ZX0sIm9uQmVoYWxmT2YiOnsia2luZCI6InVzZXIiLCJfaWQiOiI2NDJhNTNiNTE2ZDRkODI5M2M5YjdiNzgiLCJ1c2VyIjoicm9nZXJ4YXZpZXIifSwiaWF0IjoxNzE2Njg3MzU3LCJzdWIiOiIvc3BhY2VzL3JvZ2VyeGF2aWVyL29jcl93aXRoX2Zhc3RhcGkiLCJleHAiOjE3MTY3NzM3NTcsImlzcyI6Imh0dHBzOi8vaHVnZ2luZ2ZhY2UuY28ifQ._sGdEgC-ijbIhLmB6iNSBQ_xHNzb4Ydb9mD0L3ByRmJSbB9ccfGbRgtNmkV1JLLldHp_VEKUSQt9Mwq_q4aGAQ',
216
- # 'Dnt': '1',
217
- # 'Priority': 'u=1, i',
218
- # 'Sec-Ch-Ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
219
- # 'Sec-Ch-Ua-Mobile': '?0',
220
- # 'Sec-Ch-Ua-Platform': '"Windows"',
221
- # 'Sec-Fetch-Dest': 'empty',
222
- # 'Sec-Fetch-Mode': 'cors',
223
- # 'Sec-Fetch-Site': 'same-origin',
224
- # 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
225
- # }
226
  files = {
227
  "image": image_bytes,
228
  }
229
  try:
230
- # resp = requests.post("https://rogerxavier-ocr-with-fastapi.hf.space/getCoordinates", files=files,headers=headers)#还是有header才能跑
231
- resp = requests.post("https://rogerxavier-ocr-with-fastapi.hf.space/getCoordinates", files=files)#不用header看看会不会还限制
232
  #先json转换,0为坐标list合集,1为 boxid和text合集
233
  boxCoordinates , boxInfo = resp.json()[0],resp.json()[1] #分别是list和dict类型
234
  print("ofa ocr识别漫画块成功返回")
@@ -249,9 +261,6 @@ def get_sorted_dialog_text(image_path:"包含后缀的文件路径")->"返回排
249
 
250
  # 调用函数并打印结果
251
  associate_text_list,related_groups = find_associate_text(sorted_indices,centers,sorted_coordinates,boxInfo)
252
- #print("相关list是",associate_text_list)
253
- #print("related_groups是",related_groups)
254
- #print("sorted_indices是",sorted_indices)
255
 
256
  related_groups = sort_associate_text_list(sorted_indices,related_groups,boxCoordinates,centers)
257
 
@@ -473,20 +482,6 @@ if __name__ == '__main__':
473
  if filename is not None:
474
  print("存放临时mp3文件的路径是",filename)
475
 
476
- #含字幕版
477
- # clip = ImageClip(img).set_duration(duration).resize((width, height)) # 初始clip
478
-
479
- # txt_clip = TextClip(cur_copywrite, fontsize=40, color='white', bg_color='black',
480
- # font=font_path) ##文本clip后加入视频
481
-
482
- # txt_clip = txt_clip.set_pos(('center', 'bottom')).set_duration(duration)
483
- # # 创建音频剪辑
484
- # audio_clip = AudioFileClip(filename)
485
- # clip = clip.set_audio(audio_clip) # 将音频与视频片段关联
486
- # clip = CompositeVideoClip([clip, txt_clip])
487
- # video_clips.append(clip)
488
- #含字幕版
489
-
490
  #不含字幕版
491
  clip = ImageClip(img).set_duration(duration).resize((width, height))
492
 
 
33
  print("azure_service_region是",azure_service_region)
34
  print("my_openai_key",my_openai_key)
35
 
36
+
37
+ from faker import Faker
38
+ fake = Faker()
39
+ fake_user_agent = fake.user_agent()
40
+ fake_headers = {
41
+ 'scheme': 'https',
42
+ 'Accept': '*/*',
43
+ 'Accept-Encoding': 'gzip, deflate, br, zstd',
44
+ 'Accept-Language': 'zh-CN,zh;q=0.9',
45
+ 'Dnt': '1',
46
+ 'Priority': 'u=1, i',
47
+ 'Sec-Ch-Ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
48
+ 'Sec-Ch-Ua-Mobile': '?0',
49
+ 'Sec-Ch-Ua-Platform': '"Windows"',
50
+ 'Sec-Fetch-Dest': 'empty',
51
+ 'Sec-Fetch-Mode': 'cors',
52
+ 'Sec-Fetch-Site': 'same-origin',
53
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
54
+ }
55
+ fake_headers['User-Agent'] = fake_user_agent
56
+
57
+
58
+
59
  #通过去水印完整漫画图片->获取相应的对话框图片->获取对话框文字->返回对话框文字
60
  def get_image_copywrite(image_path:"图片路径(包含后缀)",dialog_cut_path:"对话框切割路径")->"返回漫画关联对话框识别后得到的文案str(原文即可),也可能是none":
61
  def extract_chinese(text:str)->str:
 
227
  return filtered_data
228
 
229
 
230
+ def get_sorted_dialog_text(image_path:"包含后缀的文件路径",fake_headers:dict=None)->"返回排序后的text list(一列或者几列话,反正是一个框的内容,几句不清楚,一个框的list当一次文案就行) 或者失败请求返回none":
231
+
232
+ # 创建一个Session对象
233
+ session = requests.Session()
234
+ if fake_headers is not None:
235
+ session.headers = fake_headers
236
+
237
  image_bytes = open(image_path, 'rb')
238
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  files = {
240
  "image": image_bytes,
241
  }
242
  try:
243
+ resp = session.post("https://rogerxavier-ocr-with-fastapi.hf.space/getCoordinates", files=files)#用faker header看看会不会还限制
 
244
  #先json转换,0为坐标list合集,1为 boxid和text合集
245
  boxCoordinates , boxInfo = resp.json()[0],resp.json()[1] #分别是list和dict类型
246
  print("ofa ocr识别漫画块成功返回")
 
261
 
262
  # 调用函数并打印结果
263
  associate_text_list,related_groups = find_associate_text(sorted_indices,centers,sorted_coordinates,boxInfo)
 
 
 
264
 
265
  related_groups = sort_associate_text_list(sorted_indices,related_groups,boxCoordinates,centers)
266
 
 
482
  if filename is not None:
483
  print("存放临时mp3文件的路径是",filename)
484
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
485
  #不含字幕版
486
  clip = ImageClip(img).set_duration(duration).resize((width, height))
487