HaochenGong commited on
Commit
b962465
·
1 Parent(s): bece3c1

change to html

Browse files
.idea/workspace.xml CHANGED
@@ -4,7 +4,9 @@
4
  <option name="autoReloadType" value="SELECTIVE" />
5
  </component>
6
  <component name="ChangeListManager">
7
- <list default="true" id="5e4481c0-7ba2-42e4-bbe6-4c36a0d36baa" name="Changes" comment="test auto delete">
 
 
8
  <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
9
  <change beforePath="$PROJECT_DIR$/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/app.py" afterDir="false" />
10
  </list>
@@ -17,6 +19,7 @@
17
  <option name="RECENT_TEMPLATES">
18
  <list>
19
  <option value="Python Script" />
 
20
  </list>
21
  </option>
22
  </component>
@@ -31,20 +34,22 @@
31
  <option name="hideEmptyMiddlePackages" value="true" />
32
  <option name="showLibraryContents" value="true" />
33
  </component>
34
- <component name="PropertiesComponent">{
35
- &quot;keyToString&quot;: {
36
- &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
37
- &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
38
- &quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
39
- &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
40
- &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
41
- &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
42
- &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
43
- &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
 
44
  }
45
- }</component>
46
  <component name="RecentsManager">
47
  <key name="MoveFile.RECENT_KEYS">
 
48
  <recent name="$PROJECT_DIR$/google_drive_credentials" />
49
  <recent name="$PROJECT_DIR$" />
50
  </key>
@@ -59,7 +64,7 @@
59
  <updated>1723386888312</updated>
60
  <workItem from="1723386893769" duration="12000" />
61
  <workItem from="1723386970626" duration="451000" />
62
- <workItem from="1723387453009" duration="13563000" />
63
  </task>
64
  <task id="LOCAL-00001" summary="create">
65
  <created>1723387548126</created>
@@ -166,7 +171,21 @@
166
  <option name="project" value="LOCAL" />
167
  <updated>1723458694930</updated>
168
  </task>
169
- <option name="localTasksCounter" value="16" />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  <servers />
171
  </component>
172
  <component name="TypeScriptGeneratedFilesManager">
@@ -180,6 +199,8 @@
180
  <MESSAGE value="debug" />
181
  <MESSAGE value="google drive" />
182
  <MESSAGE value="test auto delete" />
183
- <option name="LAST_COMMIT_MESSAGE" value="test auto delete" />
 
 
184
  </component>
185
  </project>
 
4
  <option name="autoReloadType" value="SELECTIVE" />
5
  </component>
6
  <component name="ChangeListManager">
7
+ <list default="true" id="5e4481c0-7ba2-42e4-bbe6-4c36a0d36baa" name="Changes" comment="complete log part">
8
+ <change afterPath="$PROJECT_DIR$/layout/web_page.css" afterDir="false" />
9
+ <change afterPath="$PROJECT_DIR$/layout/web_page.html" afterDir="false" />
10
  <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
11
  <change beforePath="$PROJECT_DIR$/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/app.py" afterDir="false" />
12
  </list>
 
19
  <option name="RECENT_TEMPLATES">
20
  <list>
21
  <option value="Python Script" />
22
+ <option value="HTML File" />
23
  </list>
24
  </option>
25
  </component>
 
34
  <option name="hideEmptyMiddlePackages" value="true" />
35
  <option name="showLibraryContents" value="true" />
36
  </component>
37
+ <component name="PropertiesComponent"><![CDATA[{
38
+ "keyToString": {
39
+ "DefaultHtmlFileTemplate": "HTML File",
40
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
41
+ "RunOnceActivity.ShowReadmeOnStart": "true",
42
+ "WebServerToolWindowFactoryState": "false",
43
+ "node.js.detected.package.eslint": "true",
44
+ "node.js.detected.package.tslint": "true",
45
+ "node.js.selected.package.eslint": "(autodetect)",
46
+ "node.js.selected.package.tslint": "(autodetect)",
47
+ "vue.rearranger.settings.migration": "true"
48
  }
49
+ }]]></component>
50
  <component name="RecentsManager">
51
  <key name="MoveFile.RECENT_KEYS">
52
+ <recent name="$PROJECT_DIR$/web_design" />
53
  <recent name="$PROJECT_DIR$/google_drive_credentials" />
54
  <recent name="$PROJECT_DIR$" />
55
  </key>
 
64
  <updated>1723386888312</updated>
65
  <workItem from="1723386893769" duration="12000" />
66
  <workItem from="1723386970626" duration="451000" />
67
+ <workItem from="1723387453009" duration="19315000" />
68
  </task>
69
  <task id="LOCAL-00001" summary="create">
70
  <created>1723387548126</created>
 
171
  <option name="project" value="LOCAL" />
172
  <updated>1723458694930</updated>
173
  </task>
174
+ <task id="LOCAL-00016" summary="test auto monitor">
175
+ <created>1723461444926</created>
176
+ <option name="number" value="00016" />
177
+ <option name="presentableId" value="LOCAL-00016" />
178
+ <option name="project" value="LOCAL" />
179
+ <updated>1723461444926</updated>
180
+ </task>
181
+ <task id="LOCAL-00017" summary="complete log part">
182
+ <created>1723462386739</created>
183
+ <option name="number" value="00017" />
184
+ <option name="presentableId" value="LOCAL-00017" />
185
+ <option name="project" value="LOCAL" />
186
+ <updated>1723462386739</updated>
187
+ </task>
188
+ <option name="localTasksCounter" value="18" />
189
  <servers />
190
  </component>
191
  <component name="TypeScriptGeneratedFilesManager">
 
199
  <MESSAGE value="debug" />
200
  <MESSAGE value="google drive" />
201
  <MESSAGE value="test auto delete" />
202
+ <MESSAGE value="test auto monitor" />
203
+ <MESSAGE value="complete log part" />
204
+ <option name="LAST_COMMIT_MESSAGE" value="complete log part" />
205
  </component>
206
  </project>
app.py CHANGED
@@ -309,41 +309,53 @@ def new_example_inference_3():
309
  # complete_result_dataframe.visible = not complete_result_dataframe.visible
310
 
311
 
312
- demo = gr.Blocks()
313
- with demo:
314
- gr.Markdown("# Cpp4App\n\n**Automated Contextual Privacy Policies Generation for Mobile Apps**"
315
- "\n\nThere are two inputs to generate CPP for a mobile app: app's privacy policy URL link and a GUI screenshot")
316
 
317
- with gr.Row():
318
- example_image_1 = gr.Image(value="examples/6-8.jpg", label="Example 1")
319
- example_image_2 = gr.Image(value="examples/11-9.jpg", label="Example 2")
320
- example_image_3 = gr.Image(value="examples/1-1.jpg", label="Example 3")
321
- with gr.Column():
322
- gr.Markdown("**You can try with three examples we provided:**"
323
- "\n\n- WhatsApp"
324
- "\n\n- Snap"
325
- "\n\n- Mcdonald's"
326
- "\n\n**You can also try with your own example:**"
327
- "\n\nUpload the screenshot and privacy policy URL link, then click 'submit' button"
328
- # "\n\n"
329
- # "\n\nThe three provided examples are pre-run, while your own screenshot needs to run for approximately one minute."
330
- )
331
 
332
- with gr.Row():
333
- example_button_1 = gr.Button("Run with Example 1")
334
- example_button_2 = gr.Button("Run with Example 2")
335
- example_button_3 = gr.Button("Run with Example 3")
336
- with gr.Column():
337
- clear_button = gr.Button("Clear")
338
- submit_button = gr.Button("Submit")
339
 
340
- with gr.Row():
341
- text_input = gr.Textbox(label="URL Input for the Privacy Policy of the App")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
 
343
- with gr.Column():
344
- image_input = gr.Image(type="pil", label="Screenshot Upload")
345
- result_image = gr.Image(type="pil", label="Result Screenshot")
 
 
 
 
346
 
 
 
 
 
 
 
 
347
  with gr.Row():
348
  result_dataframe = gr.Dataframe(type="pandas", label="Result Excel (Summarized)")
349
 
@@ -377,13 +389,13 @@ with demo:
377
  submit_button.click(inference, inputs=[image_input, text_input], outputs=[result_image, result_dataframe, complete_result_dataframe])
378
  clear_button.click(lambda: [None, None, None, None, None, None], inputs=[], outputs=[image_input, text_input, result_image, result_dataframe, complete_result_dataframe])
379
  # example_button.click(example_inference, inputs=[], outputs=[image_input, text_input, result_image, result_dataframe])
380
- example_button_1.click(new_example_inference_1,
381
  inputs=[],
382
  outputs=[image_input, text_input, result_image, result_dataframe, complete_result_dataframe])
383
- example_button_2.click(new_example_inference_2,
384
  inputs=[],
385
  outputs=[image_input, text_input, result_image, result_dataframe, complete_result_dataframe])
386
- example_button_3.click(new_example_inference_3,
387
  inputs=[],
388
  outputs=[image_input, text_input, result_image, result_dataframe, complete_result_dataframe])
389
 
 
309
  # complete_result_dataframe.visible = not complete_result_dataframe.visible
310
 
311
 
312
+ with open('layout/web_page.html', 'r', encoding='utf-8') as file:
313
+ html_content = file.read()
 
 
314
 
315
+ with gr.Blocks() as demo:
316
+ gr.HTML(html_content)
 
 
 
 
 
 
 
 
 
 
 
 
317
 
318
+ eg_btn1 = gr.Button("Example 1", elem_id="example1", visible=False)
319
+ eg_btn2 = gr.Button("Example 2", elem_id="example2", visible=False)
320
+ eg_btn3 = gr.Button("Example 3", elem_id="example4", visible=False)
 
 
 
 
321
 
322
+ clear_button = gr.Button("Clear", elem_id="clear", visible=False)
323
+ submit_button = gr.Button("Submit", elem_id="submit", visible=False)
324
+
325
+ text_input = gr.Textbox(label="URL Input for the Privacy Policy of the App", elem_id="text_input", visible=False)
326
+ image_input = gr.Image(type="pil", label="Screenshot Upload", elem_id="image_input", visible=False)
327
+ result_image = gr.Image(type="pil", label="Result Screenshot", elem_id="image_output", visible=False)
328
+
329
+ # with gr.Row():
330
+ # example_image_1 = gr.Image(value="examples/6-8.jpg", label="Example 1")
331
+ # example_image_2 = gr.Image(value="examples/11-9.jpg", label="Example 2")
332
+ # example_image_3 = gr.Image(value="examples/1-1.jpg", label="Example 3")
333
+ # with gr.Column():
334
+ # gr.Markdown("**You can try with three examples we provided:**"
335
+ # "\n\n- WhatsApp"
336
+ # "\n\n- Snap"
337
+ # "\n\n- Mcdonald's"
338
+ # "\n\n**You can also try with your own example:**"
339
+ # "\n\nUpload the screenshot and privacy policy URL link, then click 'submit' button"
340
+ # # "\n\n"
341
+ # # "\n\nThe three provided examples are pre-run, while your own screenshot needs to run for approximately one minute."
342
+ # )
343
 
344
+ # with gr.Row():
345
+ # example_button_1 = gr.Button("Run with Example 1")
346
+ # example_button_2 = gr.Button("Run with Example 2")
347
+ # example_button_3 = gr.Button("Run with Example 3")
348
+ # with gr.Column():
349
+ # clear_button = gr.Button("Clear")
350
+ # submit_button = gr.Button("Submit")
351
 
352
+ # with gr.Row():
353
+ # text_input = gr.Textbox(label="URL Input for the Privacy Policy of the App", elem_id="text_input", visible=False)
354
+ #
355
+ # with gr.Column():
356
+ # image_input = gr.Image(type="pil", label="Screenshot Upload")
357
+ # result_image = gr.Image(type="pil", label="Result Screenshot")
358
+ #
359
  with gr.Row():
360
  result_dataframe = gr.Dataframe(type="pandas", label="Result Excel (Summarized)")
361
 
 
389
  submit_button.click(inference, inputs=[image_input, text_input], outputs=[result_image, result_dataframe, complete_result_dataframe])
390
  clear_button.click(lambda: [None, None, None, None, None, None], inputs=[], outputs=[image_input, text_input, result_image, result_dataframe, complete_result_dataframe])
391
  # example_button.click(example_inference, inputs=[], outputs=[image_input, text_input, result_image, result_dataframe])
392
+ eg_btn1.click(new_example_inference_1,
393
  inputs=[],
394
  outputs=[image_input, text_input, result_image, result_dataframe, complete_result_dataframe])
395
+ eg_btn2.click(new_example_inference_2,
396
  inputs=[],
397
  outputs=[image_input, text_input, result_image, result_dataframe, complete_result_dataframe])
398
+ eg_btn3.click(new_example_inference_3,
399
  inputs=[],
400
  outputs=[image_input, text_input, result_image, result_dataframe, complete_result_dataframe])
401
 
layout/images/eg1.jpg ADDED
layout/images/eg2.jpg ADDED
layout/images/eg3.jpg ADDED
layout/images/head.jpg ADDED
layout/images/point.png ADDED
layout/web_page.css ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body{
2
+ margin: 0; /* Remove the default margin */
3
+ padding: 0;
4
+ min-width: 100vw; /* Set the body's minimum width and height to the window's width and height */
5
+ min-height: 100vh;
6
+ background-color: white; /* Set the background color to white */
7
+ overflow-x: hidden; /* Hide the horizontal overflow (scrollbar only in the vertical direction) */
8
+ display: flex;
9
+ flex-direction: column; /* 按列布局 */
10
+ align-items: center;
11
+ color: rgb(40, 40, 40);
12
+ }
13
+
14
+ .title{
15
+ width: 100%;
16
+ height: 485px;
17
+ display: flex;
18
+ }
19
+
20
+ .title_half{
21
+ width: 50%;
22
+ height: 100%;
23
+ }
24
+
25
+ .title_half img{
26
+ width: 100%;
27
+ height: auto;
28
+ }
29
+
30
+ .title_content{
31
+ display: flex;
32
+ flex-direction: column; /* 按列布局 */
33
+ justify-content: center; /* 垂直方向居中 */
34
+ padding-left: 120px;
35
+ padding-right: 120px;
36
+ box-sizing: border-box;
37
+ }
38
+
39
+ .title_half p{
40
+ font-size: 22px;
41
+ font-weight: bolder;
42
+ margin-top: -10px;
43
+ }
44
+
45
+ h1{
46
+ font-size: 80px;
47
+ font-weight: bolder;
48
+ }
49
+
50
+ .choice{
51
+ display: flex;
52
+ width: 100%;
53
+ height: 80px;
54
+ margin-top: 50px;
55
+ }
56
+
57
+ .choice_btn{
58
+ width: 150px;
59
+ height: 50px;
60
+ display: flex;
61
+ flex-direction: column; /* 按列布局 */
62
+ justify-content: center; /* 垂直方向居中 */
63
+ align-items: center;
64
+ border-radius: 5px;
65
+ transition: color 0.3s ease, background-color 0.3s ease;
66
+ }
67
+
68
+ .start{
69
+ background-color: rgb(40, 40, 40);
70
+ color: white;
71
+ margin-right: 20px;
72
+ text-decoration: none;
73
+ }
74
+
75
+ .start:hover{
76
+ background-color: rgb(117, 209, 255);
77
+ }
78
+
79
+ .view_examples{
80
+ color: rgb(40, 40, 40);
81
+ }
82
+
83
+ .view_examples:hover{
84
+ color: rgb(24, 157, 246);
85
+ }
86
+
87
+ .examples{
88
+ width: 84%;
89
+ margin-top: 80px;
90
+ }
91
+
92
+ .head{
93
+ width: 100%;
94
+ display: flex;
95
+ justify-content: space-between;
96
+ }
97
+
98
+ h2{
99
+ font-size: 47px;
100
+ font-weight: bolder;
101
+ }
102
+
103
+ .examples p{
104
+ font-size: 18px;
105
+ font-weight: bolder;
106
+ margin-top: -10px;
107
+ margin-bottom: 50px;
108
+ }
109
+
110
+ .img_box{
111
+ display: flex;
112
+ justify-content: space-between;
113
+ }
114
+
115
+ .eg{
116
+ width: 25%;
117
+ }
118
+
119
+ .eg img{
120
+ width: 100%;
121
+ height: auto;
122
+ border: 3px solid rgb(188, 204, 212);
123
+ transition: border-color 0.5s ease, border-width 0.5s ease;
124
+ border-radius: 10px;
125
+ cursor: pointer;
126
+ }
127
+
128
+ .eg img:hover{
129
+ border-color: rgb(117, 209, 255); /* 悬停时边框颜色 */
130
+ border-width: 3px; /* 悬停时边框粗细 */
131
+ }
132
+
133
+ .eg p{
134
+ width: 100%;
135
+ height: 60px;
136
+ display: flex;
137
+ flex-direction: column; /* 按列布局 */
138
+ justify-content: center; /* 垂直方向居中 */
139
+ align-items: center;
140
+ margin: 0;
141
+ font-style: italic;
142
+ }
143
+
144
+
145
+ .workspace{
146
+ width: 84%;
147
+ margin-top: 80px;
148
+ margin-bottom: 180px;
149
+ display: flex;
150
+ flex-direction: column; /* 按列布局 */
151
+ align-items: center;
152
+ }
153
+
154
+ .workspace_btn{
155
+ width: 350px;
156
+ display: flex;
157
+ justify-content: space-between; /* 垂直方向居中 */
158
+ align-items: center;
159
+ }
160
+
161
+ .btn{
162
+ width: 150px;
163
+ height: 45px;
164
+ border: 2px solid rgb(40, 40, 40);
165
+ transition: border-color 0.3s ease, color 0.3s ease, background-color 0.3s ease;
166
+ border-radius: 2px;
167
+ cursor: pointer;
168
+ }
169
+
170
+ .run{
171
+ color: white;
172
+ background-color: rgb(40, 40, 40);
173
+ }
174
+
175
+ .btn:hover{
176
+ color: white;
177
+ background-color: rgb(117, 209, 255);
178
+ border: white;
179
+ }
180
+
181
+ .space{
182
+ width: 80%;
183
+ }
184
+
185
+ label{
186
+ font-size: 18px;
187
+ font-weight: bolder;
188
+ }
189
+
190
+ .step1{
191
+ display: flex;
192
+ flex-direction: column; /* 按列布局 */
193
+ margin-top: 30px;
194
+ }
195
+
196
+ .url{
197
+ height: 50px;
198
+ margin-top: 20px;
199
+ margin-bottom: 100px;
200
+ font-size: 20px;
201
+ color: rgb(194, 194, 194);
202
+ padding-left: 10px;
203
+ border: 2px solid rgb(40, 40, 40);
204
+ border-radius: 5px;
205
+ }
206
+
207
+ .step2{
208
+ display: flex;
209
+ justify-content: space-between;
210
+ }
211
+
212
+ .img{
213
+ display: flex;
214
+ flex-direction: column; /* 按列布局 */
215
+ width: 40%;
216
+ }
217
+
218
+ .point{
219
+ width: 18%;
220
+ display: flex;
221
+ flex-direction: column; /* 按列布局 */
222
+ justify-content: center;
223
+ align-items: center;
224
+ }
225
+
226
+ .point img{
227
+ width: 80%;
228
+ height: auto;
229
+ }
230
+
231
+ .phone{
232
+ width: 100%;
233
+ height: 750px;
234
+ border: 2px solid rgb(40, 40, 40);
235
+ border-radius: 5px;
236
+ margin-top: 20px;
237
+ }
layout/web_page.html ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Cpp4App Test</title>
6
+ <link rel="stylesheet" type="text/css" href="web_page.css">
7
+ </head>
8
+ <body>
9
+
10
+ <div class="title">
11
+ <div class="title_half title_content">
12
+ <h1>Cpp4App</h1>
13
+ <p>Automated Contextual Privacy Policies Generation for Mobile Apps.</p>
14
+ <div class="choice">
15
+ <a href="#workspace" class="start choice_btn">START</a>
16
+ <a href="#examples" class="view_examples choice_btn">View examples</a>
17
+ </div>
18
+ </div>
19
+ <div class="title_half">
20
+ <img src="images/head.jpg" alt="">
21
+ </div>
22
+ </div>
23
+
24
+ <div class="examples" id="examples">
25
+ <div class="head">
26
+ <h2>EXAMPLES</h2>
27
+ </div>
28
+ <p>Click to run the example !</p>
29
+ <div class="img_box">
30
+ <div class="eg">
31
+ <a href="#step2"><img src="images/eg1.jpg" alt=""></a>
32
+ <p>· WhatsApp</p>
33
+ </div>
34
+ <div class="eg">
35
+ <a href="#step2"><img src="images/eg2.jpg" alt=""></a>
36
+ <p>· Snap</p>
37
+ </div>
38
+ <div class="eg">
39
+ <a href="#step2"><img src="images/eg3.jpg" alt=""></a>
40
+ <p>· Mcdonald's</p>
41
+ </div>
42
+ </div>
43
+ </div>
44
+
45
+ <div class="workspace" id="workspace">
46
+ <div class="head">
47
+ <h2>WORKSPACE</h2>
48
+ <div class="workspace_btn">
49
+ <input class="btn run" type="submit" value="RUN">
50
+ <button class="btn reset">RESET</button>
51
+ </div>
52
+ </div>
53
+
54
+ <div class="space">
55
+ <div class="step1">
56
+ <label for="inputBox">Step 1 : Input privacy policy URL</label>
57
+ <input class="url" type="text" id="inputBox" name="inputBox" placeholder="Privacy Policy URL Link" />
58
+ </div>
59
+
60
+ <div class="step2" id="step2">
61
+ <div class="img">
62
+ <label for="image-input">Step 2 : Upload the screenshot</label>
63
+ <input type="file" accept="image/*" id="image-input" class="phone">
64
+ </div>
65
+ <div class="point"><img src="images/point.png" alt=""></div>
66
+ <div class="img">
67
+ <label for="output">Outcome :</label>
68
+ <div class="phone" id="output">
69
+ <img src="" alt="">
70
+ <div class="left next_btn"></div>
71
+ <div class="right next_btn"></div>
72
+ </div>
73
+ </div>
74
+ </div>
75
+ </div>
76
+ </div>
77
+
78
+ <script>
79
+ // 监听示例图片的点击事件
80
+ document.querySelectorAll('.eg a').forEach(function(element) {
81
+ element.addEventListener('click', function(event) {
82
+ event.preventDefault(); // 阻止默认行为
83
+
84
+ // 根据点击的图片选择运行不同的 Gradio 函数
85
+ const exampleIndex = Array.from(element.parentElement.parentElement.children).indexOf(element.parentElement) + 1;
86
+ if (exampleIndex === 1) {
87
+ gradioApp().querySelector('button[gr-button-id="example1"]').click();
88
+ } else if (exampleIndex === 2) {
89
+ gradioApp().querySelector('button[gr-button-id="example2"]').click();
90
+ } else if (exampleIndex === 3) {
91
+ gradioApp().querySelector('button[gr-button-id="example3"]').click();
92
+ }
93
+ });
94
+ });
95
+
96
+ // 绑定 "RUN" 按钮到 Gradio 的 submit_button
97
+ document.querySelector('input.btn.run').addEventListener('click', function(event) {
98
+ event.preventDefault(); // 阻止表单默认提交行为
99
+ gradioApp().querySelector('button[gr-button-id="submit_button"]').click();
100
+ });
101
+
102
+ // 绑定 "RESET" 按钮到 Gradio 的 clear_button
103
+ document.querySelector('button.btn.reset').addEventListener('click', function() {
104
+ gradioApp().querySelector('button[gr-button-id="clear_button"]').click();
105
+ });
106
+
107
+ // 监听 URL 输入框的输入事件
108
+ document.querySelector('#inputBox').addEventListener('input', function(event) {
109
+ const grInput = gradioApp().querySelector('textarea#text_input');
110
+ grInput.value = event.target.value;
111
+
112
+ // 手动触发 Gradio 输入框的事件
113
+ const inputEvent = new Event('input', { bubbles: true });
114
+ grInput.dispatchEvent(inputEvent);
115
+ });
116
+
117
+ // 监听图片上传的文件选择事件
118
+ document.querySelector('#image-input').addEventListener('change', function(event) {
119
+ const file = event.target.files[0];
120
+ if (file) {
121
+ const reader = new FileReader();
122
+ reader.onload = function(e) {
123
+ const img = new Image();
124
+ img.src = e.target.result;
125
+
126
+ img.onload = function() {
127
+ const canvas = document.createElement('canvas');
128
+ canvas.width = img.width;
129
+ canvas.height = img.height;
130
+ const ctx = canvas.getContext('2d');
131
+ ctx.drawImage(img, 0, 0);
132
+
133
+ // 获取图像的 DataURL 并设置为 Gradio 的隐藏输入框值
134
+ const dataURL = canvas.toDataURL('image/png');
135
+ const grImageInput = gradioApp().querySelector('textarea#image_input');
136
+ grImageInput.value = dataURL;
137
+
138
+ // 手动触发 Gradio 输入框的事件
139
+ const inputEvent = new Event('input', { bubbles: true });
140
+ grImageInput.dispatchEvent(inputEvent);
141
+ };
142
+ };
143
+ reader.readAsDataURL(file);
144
+ }
145
+ });
146
+ </script>
147
+
148
+ </body>
149
+ </html>