Skip to content

Commit

Permalink
1.修复中文exe不能打开的bug 2.增加可配置后端ip的功能->config.json 3.修复ffmpeg添加PATH的错误 4、增…
Browse files Browse the repository at this point in the history
…加打包文件中ffmpeg的dll
  • Loading branch information
m986883511 committed Aug 2, 2021
1 parent 0f1413f commit 986f422
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ docker run -d -p 6666:6666 m986883511/extract_subtitles

后端接口容器地址[Docker Hub](https://hub.docker.com/repository/docker/m986883511/extract_subtitles)

此过程可能时间较长,您需要预先安装好好docker,并配置好docker加速器
此过程可能时间较长,您需要预先安装好好docker,并配置好docker加速器,你可能需要先docker login

```shell
docker run -d -p 6666:6666 m986883511/extract_subtitles
Expand Down
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ip": "127.0.0.1",
"port": "6666"
}
Binary file modified image/2-run-exe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 16 additions & 4 deletions interface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
import os

import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder

Expand All @@ -10,19 +10,30 @@ class ExtractSubtitleApi:
debug = True

def __init__(self):
self.ip = ExtractSubtitleApi.ip
self.port = ExtractSubtitleApi.port
self.set_ip_port()
self.headers = {'content-type': 'application/json'}
self.print_flag = True

def set_ip_port(self):
try:
with open(os.path.join(os.path.dirname(__file__), 'config.json')) as f:
content = f.read()
content = json.loads(content)
self.ip = content['ip']
self.port = content['port']
except Exception as e:
print('read config.json failed, err={}'.format(e))
self.ip = ExtractSubtitleApi.ip
self.port = ExtractSubtitleApi.port

@property
def base_url(self):
return "http://{}:{}".format(self.ip, self.port)

def text_recognition(self, base64_img):
url = '{}/text_recognition'.format(self.base_url)
data = {"image": [base64_img]}
res = requests.post(url, data=data)
res = requests.post(url, data=data)
return self.deal_with_response(res)

def extract_human_voice_from_sound(self, local_mp3_filepath):
Expand All @@ -43,6 +54,7 @@ def get_human_voice_time_point(self, remote_wav_filename):
return self.deal_with_response(res)

def detect_recognition_model(self):
self.set_ip_port()
url = '{}/load_model'.format(self.base_url)
response = requests.get(url, headers=self.headers)
return self.deal_with_response(response)
Expand Down
19 changes: 10 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import base64

current_dir = os.path.dirname(__file__)
sys.path.append(os.path.join(current_dir, 'ffmpeg'))
os.environ['PATH'] += ';' + os.path.join(current_dir, 'ffmpeg')

import cv2
import srt
Expand Down Expand Up @@ -340,15 +340,16 @@ def __deal_with_process_output_string(self, input_str):

def test_connect_api(self):
self.add_log('开始测试api接口是否连通')
value = self.api_interface.detect_recognition_model()
if isinstance(value, dict) and value.get('result') == 'load model success':
msg = '文字识别API接口已连通:{}'.format(self.api_interface.base_url)
self.add_log(msg)
try:
value = self.api_interface.detect_recognition_model()
if isinstance(value, dict) and value.get('result') == 'load model success':
msg = '文字识别API接口已连通:{}'.format(self.api_interface.base_url)
self.add_log(msg)
self.connect_api_lineedit.setText(msg)
except Exception as e:
msg = '无法连接文字识别API接口,检查容器状态后重试'
self.add_log('{}, err={}'.format(msg, e))
self.connect_api_lineedit.setText(msg)
return
msg = '无法连接文字识别API接口'
self.add_log(msg)
self.connect_api_lineedit.setText(msg)

def update_progress_bar(self, progress):
self.extract_progress.setValue(progress)
Expand Down

0 comments on commit 986f422

Please sign in to comment.