beihai commited on
Commit
3e6a3ef
1 Parent(s): cb9970a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +64 -45
index.html CHANGED
@@ -1,57 +1,76 @@
1
  <!DOCTYPE html>
2
  <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>Gradio-Lite: Serverless Gradio Running Entirely in Your Browser</title>
7
- <meta name="description" content="Gradio-Lite: Serverless Gradio Running Entirely in Your Browser">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
- <script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
10
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
11
-
12
- <style>
13
- html, body {
14
- margin: 0;
15
- padding: 0;
16
- height: 100%;
17
- }
18
- </style>
19
- </head>
20
- <body>
21
- <gradio-lite>
22
- <gradio-file name="app.py" entrypoint>
23
  import gradio as gr
 
24
 
25
- from filters import as_gray
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- def process(input_image):
28
- output_image = as_gray(input_image)
29
- return output_image
 
 
 
 
 
30
 
31
- demo = gr.Interface(
32
- process,
33
- "image",
34
- "image",
35
- examples=["lion.jpg", "logo.png"],
36
  )
37
 
38
- demo.launch()
39
- </gradio-file>
40
-
41
- <gradio-file name="filters.py">
42
- from skimage.color import rgb2gray
43
-
44
- def as_gray(image):
45
- return rgb2gray(image)
46
- </gradio-file>
47
-
48
- <gradio-file name="lion.jpg" url="https://raw.githubusercontent.com/gradio-app/gradio/main/gradio/test_data/lion.jpg" />
49
- <gradio-file name="logo.png" url="https://raw.githubusercontent.com/gradio-app/gradio/main/guides/assets/logo.png" />
50
 
51
- <gradio-requirements>
52
- # Same syntax as requirements.txt
53
- scikit-image
54
- </gradio-requirements>
55
- </gradio-lite>
56
  </body>
57
  </html>
 
1
  <!DOCTYPE html>
2
  <html>
3
+ <head>
4
+ <!-- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto&display=swap" > -->
5
+ <style>
6
+ body {
7
+ font-family: 'Roboto', sans-serif;
8
+ font-size: 16px;
9
+ }
10
+ .logo {
11
+ height: 1em;
12
+ vertical-align: middle;
13
+ margin-bottom: 0.1em;
14
+ }
15
+ </style>
16
+
17
+ <script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite@0.4.1/dist/lite.js"></script>
18
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite@0.4.1/dist/lite.css" />
19
+ </head>
20
+ <body>
21
+ <h2>
22
+ <!-- <img src="lite-logo.png" alt="logo" class="logo"> -->
23
+ Gradio-lite (Gradio running entirely in your browser!)
24
+ </h2>
25
+ <p>Try it out! Once the Gradio app loads (can take 10-15 seconds), disconnect your Wifi and the machine learning model will still work!</p>
26
+ <gradio-lite>
27
 
28
+ <gradio-file name="app.py" entrypoint>
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  import gradio as gr
30
+ from tempfile import NamedTemporaryFile
31
 
32
+ def translate_subtitles(english_srt, translated_json):
33
+ with open(english_srt, 'r', encoding='utf-8') as file:
34
+ english_subtitles = file.read().strip().split('\n\n')
35
+
36
+ with open(translated_json, 'r', encoding='utf-8') as file:
37
+ translated_texts = eval(file.read())
38
+ # 将上传的JSON文件内容转化为字典
39
+ # 确保翻译文本的数量与SRT文件中的条目数量相同
40
+ assert len(translated_texts) == len(english_subtitles)
41
+
42
+ # 用来存储最终翻译的SRT内容
43
+ translated_srt_content = []
44
+
45
+ # 遍历SRT文件中的每个条目,并用翻译后的文本替换原文本
46
+ for index, block in enumerate(english_subtitles):
47
+ lines = block.split('\n')
48
+ translated_srt_content.append(lines[0]) # 序号
49
+ translated_srt_content.append(lines[1]) # 时间轴
50
+ translated_srt_content.append(translated_texts[index]) # 翻译文本
51
+ translated_srt_content.append('') # 添加空行作为字幕块的分隔
52
+
53
+ # 将列表转换为字符串,每个元素之间以换行符连接
54
+ translated_srt_string = '\n'.join(translated_srt_content)
55
+ with NamedTemporaryFile(delete=False, suffix='.srt', mode='w', encoding='utf-8') as tmp_file:
56
+ tmp_file.write(translated_srt_string)
57
+ return tmp_file.name # 返回文件路径以便下载
58
 
59
+ # 创建Gradio接
60
+ iface = gr.Interface(
61
+ fn=translate_subtitles,
62
+ inputs=[
63
+ gr.File(label="Upload English SRT File"),
64
+ gr.File(label="Upload Translated Texts JSON File")
65
+ ],
66
+ outputs=gr.File(label="Download Translated SRT File")
67
 
 
 
 
 
 
68
  )
69
 
70
+ # 启动Gradio界面
71
+ iface.launch()
72
+ </gradio-file>
 
 
 
 
 
 
 
 
 
73
 
74
+ </gradio-lite>
 
 
 
 
75
  </body>
76
  </html>