Spaces:
Running
Running
Update index.html
Browse files- index.html +66 -54
index.html
CHANGED
@@ -1,57 +1,69 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
}
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
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 lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<title>Parent Page with Gradio Embed</title>
|
6 |
+
<style>
|
7 |
+
body, html {
|
8 |
+
margin: 0;
|
9 |
+
padding: 0;
|
10 |
+
height: 100vh;
|
11 |
+
width: 100vw;
|
12 |
+
overflow: hidden;
|
13 |
+
}
|
14 |
+
iframe {
|
15 |
+
width: 100%;
|
16 |
+
height: 100%;
|
17 |
+
border: none;
|
18 |
+
display: block;
|
19 |
+
}
|
20 |
+
</style>
|
21 |
+
</head>
|
22 |
+
<body>
|
23 |
+
<!-- Embed the Gradio app in an iframe -->
|
24 |
+
<iframe
|
25 |
+
id="gradioFrame"
|
26 |
+
src="https://e4d417385887b7e801.gradio.live"
|
27 |
+
sandbox="allow-same-origin allow-scripts allow-modals allow-popups allow-popups-to-escape-sandbox allow-top-navigation-by-user-activation"
|
28 |
+
allow="clipboard-write">
|
29 |
+
</iframe>
|
30 |
+
<script>
|
31 |
+
// 监听来自iframe的消息
|
32 |
+
window.addEventListener("message", (event) => {
|
33 |
+
if (event.data && event.data.type === "request_parent_url") {
|
34 |
+
event.source.postMessage({
|
35 |
+
type: "parent_url",
|
36 |
+
url: window.location.href
|
37 |
+
}, event.origin);
|
38 |
+
}
|
39 |
+
// 添加对链接点击事件的处理
|
40 |
+
if (event.data && event.data.type === "link_click") {
|
41 |
+
window.open(event.data.url, '_blank');
|
42 |
+
}
|
43 |
+
});
|
44 |
+
// 在iframe加载完成后注入脚本
|
45 |
+
document.getElementById('gradioFrame').onload = function() {
|
46 |
+
try {
|
47 |
+
const frame = document.getElementById('gradioFrame');
|
48 |
+
frame.contentWindow.postMessage({
|
49 |
+
type: "inject_script",
|
50 |
+
script: `
|
51 |
+
document.addEventListener('click', function(e) {
|
52 |
+
const link = e.target.closest('a');
|
53 |
+
if (link) {
|
54 |
+
e.preventDefault();
|
55 |
+
window.parent.postMessage({
|
56 |
+
type: 'link_click',
|
57 |
+
url: link.href
|
58 |
+
}, '*');
|
59 |
}
|
60 |
+
});
|
61 |
+
`
|
62 |
+
}, '*');
|
63 |
+
} catch(e) {
|
64 |
+
console.error('Failed to inject script:', e);
|
65 |
+
}
|
66 |
+
};
|
67 |
+
</script>
|
68 |
+
</body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
</html>
|