dabgy commited on
Commit
9a9078c
·
1 Parent(s): f3edae4
Files changed (1) hide show
  1. app.py +126 -0
app.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #!/usr/bin/python3.11
3
+
4
+ import sys, os
5
+ os.system('uname -a')
6
+ os.system('id')
7
+ os.system('cat /etc/os-release')
8
+
9
+ from datetime import datetime
10
+ app_start_time = datetime.now().strftime("%y-%m-%d_%H:%M:%S_%f")
11
+ print('App start time: ', app_start_time)
12
+
13
+ import glob
14
+
15
+ # print("trying to import backend")
16
+ # print('finish importing backend')
17
+
18
+ print("trying to import gradio")
19
+ import gradio as gr
20
+ print('finish importing gradio')
21
+
22
+ ############################################################
23
+
24
+ def greet(video, enable_area, ymin, ymax, xmin, xmax):
25
+ os.system('./videosubfinder-cli-cpu-static-linux-x64/VideoSubFinderCli.run --help')
26
+
27
+ print('输入的文件为', video)
28
+
29
+ debug_output = ""
30
+ srt_file_content = ""
31
+ srt_file_path = None
32
+
33
+ if not video:
34
+ debug_output += "ERROR: input video is not true \n"
35
+ srt_file_content = "ERROR: input video is not true"
36
+
37
+ if enable_area:
38
+ subtitle_area = (ymin, ymax, xmin, xmax)
39
+ else:
40
+ subtitle_area = None
41
+
42
+ if video:
43
+ print("检测到输入video对象,准备开始处理")
44
+ print('开始于 ', datetime.now().strftime("%y-%m-%d_%H:%M:%S_%f") )
45
+ debug_output += '开始于 ' + datetime.now().strftime("%y-%m-%d_%H:%M:%S_%f") + '\n'
46
+ ( srt_file_content , srt_file_path , sub_debug_output) = main.main(video, subtitle_area )
47
+ print('完成于 ', datetime.now().strftime("%y-%m-%d_%H:%M:%S_%f") )
48
+ debug_output += '完成于 ' + datetime.now().strftime("%y-%m-%d_%H:%M:%S_%f") + '\n'
49
+ debug_output += sub_debug_output + '\n'
50
+
51
+ print('---------运行输出结果------\n\n')
52
+ print(srt_file_content)
53
+ print('\n-------------------------\n')
54
+
55
+ if not srt_file_path or (srt_file_path and not os.path.isfile(srt_file_path) ) :
56
+ debug_output += 'ERROR: srt file path ' + srt_file_path + ' file not valid \n'
57
+ srt_file_path = None
58
+
59
+
60
+ return \
61
+ srt_file_content , \
62
+ srt_file_path, \
63
+ debug_output, \
64
+
65
+ ############################################################
66
+
67
+ allFilesGlob = '/tmp/gradio/*/**'
68
+ def getAllFiles():
69
+ all_possible_files = []
70
+ for x in glob.glob(allFilesGlob, recursive=True):
71
+ if os.path.isfile(x):
72
+ print('找到个可能文件',x)
73
+ all_possible_files.append(x)
74
+
75
+ print(all_possible_files)
76
+ return all_possible_files
77
+
78
+ def delAllFiles():
79
+ for x in glob.glob(allFilesGlob, recursive=True):
80
+ if os.path.isfile(x):
81
+ print('deleting file', x)
82
+ os.remove(x)
83
+ return "Finished deleting all files in " + allFilesGlob
84
+
85
+ ####################################################################
86
+
87
+ print('setting gradio interface')
88
+
89
+
90
+ with gr.Blocks() as app:
91
+ gr.Markdown("just test")
92
+ with gr.Tab("ttest"):
93
+ with gr.Row():
94
+ with gr.Column():
95
+ inputs = [
96
+ gr.Video(label='input video with enbedded subtitle'),
97
+ gr.Checkbox(label='enable area'),
98
+ gr.Slider(0, 10000, value=800, step=1, label="y min"),
99
+ gr.Slider(0, 10000, value=1079, step=1, label="y max"),
100
+ gr.Slider(0, 20000, value=1, step=1, label="x min"),
101
+ gr.Slider(0, 20000, value=1910, step=1, label="x max"),
102
+ ]
103
+ btn_ttest = gr.Button("Run ttest")
104
+ with gr.Column():
105
+ outputs = [
106
+ gr.Textbox(label="subtitle srt content"),
107
+ gr.File(label="output subtitle srt file"),
108
+ gr.Textbox(label="debug output"),
109
+ ]
110
+ with gr.Tab("get files"):
111
+ btn_allfiles = gr.Button("Get all files")
112
+ outputs2 = [gr.File(label='all possible files')]
113
+ with gr.Tab('del files'):
114
+ btn_delfiles = gr.Button("Delete all gradio tmp files")
115
+ outputs3 = [gr.Textbox()]
116
+
117
+ btn_ttest.click(greet, inputs=inputs, outputs=outputs)
118
+ btn_allfiles.click(getAllFiles, inputs=[], outputs=outputs2)
119
+ btn_delfiles.click(delAllFiles, inputs=[], outputs=outputs3)
120
+
121
+
122
+ # app = gr.Interface(fn=greet, inputs=inputs, outputs=outputs)
123
+
124
+ print('launching gradio app')
125
+ app.queue(max_size=30, api_open=True)
126
+ app.launch( show_error=True, server_name='0.0.0.0' )