Spaces:
Running
Running
back to oauth
Browse files- index.html +163 -13
- index.pck +0 -0
index.html
CHANGED
@@ -14,22 +14,172 @@
|
|
14 |
</script>
|
15 |
</head>
|
16 |
<body>
|
|
|
17 |
<canvas id="canvas"></canvas>
|
18 |
-
<script
|
19 |
|
20 |
<script type="module">
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
</script>
|
34 |
|
35 |
<script src="index.js"></script>
|
|
|
14 |
</script>
|
15 |
</head>
|
16 |
<body>
|
17 |
+
|
18 |
<canvas id="canvas"></canvas>
|
19 |
+
<script src="ghugging.js"></script>
|
20 |
|
21 |
<script type="module">
|
22 |
+
//console.log(window.Buffer)
|
23 |
+
//console.log(Buffer)
|
24 |
+
import { oauthLoginUrl, oauthHandleRedirectIfPresent } from "@huggingface/hub";
|
25 |
+
window.oauthLoginUrl = oauthLoginUrl;
|
26 |
+
window.oauthHandleRedirectIfPresent = oauthHandleRedirectIfPresent;
|
27 |
+
|
28 |
+
import { Client,handle_file } from "@gradio/client";
|
29 |
+
window.Client = Client;
|
30 |
+
|
31 |
+
//if has buffer huggingface signin-use that,I try to set real Buffer but faild
|
32 |
+
//window.Buffer = ArrayBuffer
|
33 |
+
|
34 |
+
|
35 |
+
// passing array seems ok others arraybuffer,unit8array faild
|
36 |
+
Client.send_image_dict = async function(hf_token,prompt,dict,_js_callback){
|
37 |
+
window.Buffer = ArrayBuffer
|
38 |
+
console.log("send_dict1")
|
39 |
+
console.log(dict)
|
40 |
+
|
41 |
+
//Error: Invalid input: must be a URL, File, Blob, or Buffer object.
|
42 |
+
//File Path not working in godot
|
43 |
+
|
44 |
+
//URL become Gradio FileData,must be start with "http"
|
45 |
+
//const file_ref = handle_file("http://localhost:8000/gradio/gradio/index.png");
|
46 |
+
//console.log(file_ref)
|
47 |
+
//Buffer is Node object
|
48 |
+
//var array = new ArrayBuffer(test);
|
49 |
+
var array1 = new Uint8Array(dict["image"]); //gradle faild
|
50 |
+
const blob1 = new Blob([array1.buffer],{type:"image/jpeg"});
|
51 |
+
const file_ref1 = handle_file(blob1)
|
52 |
+
console.log(file_ref1)
|
53 |
+
|
54 |
+
var array2 = new Uint8Array(dict["mask"]); //gradle faild
|
55 |
+
const blob2 = new Blob([array2.buffer],{type:"image/jpeg"});
|
56 |
+
const file_ref2 = handle_file(blob2)
|
57 |
+
console.log(file_ref2)
|
58 |
+
|
59 |
+
//const url = " Akjava/SimpleStableDiffusionInpaint" //"https://d798497a30149f6f35.gradio.live/" // //"http://localhost:7861"
|
60 |
+
//const url = "Kwai-Kolors/Kolors-Inpainting"
|
61 |
+
const url = "Akjava/Kolors-Inpainting"
|
62 |
+
const app = await Client.connect(url,{hf_token:hf_token,events: ["data","status"]});
|
63 |
+
const app_info = app.view_api();
|
64 |
+
console.log(app_info)
|
65 |
+
/*
|
66 |
+
const app = await Client.connect(url)
|
67 |
+
var result = await app.predict(
|
68 |
+
"/predict",{"prompt":"beautiful girl nude","image1":file_ref1,"image2":file_ref2} //send as tmp file?
|
69 |
+
)
|
70 |
+
|
71 |
+
console.log("result")
|
72 |
+
console.log(result)
|
73 |
+
|
74 |
+
_js_callback(result["data"][0].url.toString())
|
75 |
+
*/
|
76 |
+
|
77 |
+
//akjava
|
78 |
+
//const submission = app.submit("/predict", {"prompt":prompt,"image1":file_ref1,"image2":file_ref2})
|
79 |
+
const submission = app.submit("/infer", {"prompt":prompt,"image":{"background":file_ref1,"layers":[file_ref2]}
|
80 |
+
})
|
81 |
+
|
82 |
+
|
83 |
+
var result_url
|
84 |
+
for await (const msg of submission) {
|
85 |
+
if (msg.type === "data") {
|
86 |
+
console.log(msg);
|
87 |
+
console.log(msg.data);
|
88 |
+
console.log(msg["data"][0].url)
|
89 |
+
result_url = msg["data"][0].url
|
90 |
+
//_js_callback(msg["data"][0].url)
|
91 |
+
}
|
92 |
+
//
|
93 |
+
if (msg.type === "status") {
|
94 |
+
console.log(msg);
|
95 |
+
if (msg.stage == "complete"){
|
96 |
+
console.log("complete")
|
97 |
+
_js_callback(result_url)
|
98 |
+
}else if (msg.stage =="error"){
|
99 |
+
console.log("error")
|
100 |
+
_js_callback(msg.message)
|
101 |
+
}
|
102 |
+
|
103 |
+
}
|
104 |
+
}
|
105 |
+
return submission
|
106 |
+
|
107 |
+
};
|
108 |
+
|
109 |
+
Client.test1 = async function(hf_token,test,_js_callback){
|
110 |
+
|
111 |
+
console.log("array value")
|
112 |
+
|
113 |
+
//Error: Invalid input: must be a URL, File, Blob, or Buffer object.
|
114 |
+
//File Path not working in godot
|
115 |
+
|
116 |
+
//URL become Gradio FileData,must be start with "http"
|
117 |
+
//const file_ref = handle_file("http://localhost:8000/gradio/gradio/index.png");
|
118 |
+
//console.log(file_ref)
|
119 |
+
//Buffer is Node object
|
120 |
+
//var array = new ArrayBuffer(test);
|
121 |
+
var array = new Uint8Array(test); //gradle faild
|
122 |
+
|
123 |
+
const blob = new Blob([array.buffer],{type:"image/jpeg"});
|
124 |
+
//console.log(blob)
|
125 |
+
const file_ref = handle_file(blob)
|
126 |
+
console.log(file_ref)
|
127 |
+
|
128 |
+
const url = "https://b0463e8c3c0ca3103e.gradio.live" //"http://localhost:7861"
|
129 |
+
const app = await Client.connect(url)
|
130 |
+
var result = await app.predict(
|
131 |
+
"/predict",{"image1":file_ref} //send as tmp file?
|
132 |
+
)
|
133 |
+
console.log("result")
|
134 |
+
console.log(result)
|
135 |
+
console.log(result["data"][0].url)
|
136 |
+
_js_callback(result["data"][0].url.toString())
|
137 |
+
};
|
138 |
+
|
139 |
+
|
140 |
+
Client.connect2 = async function(client,url,input,_callback) {
|
141 |
+
|
142 |
+
const app = await client.connect(url,{hf_token:hf_token,events: ["data","status"]});
|
143 |
+
console.log(app.config);
|
144 |
+
const app_info = app.view_api();
|
145 |
+
console.log(app_info)
|
146 |
+
|
147 |
+
// <PREDICT VERSION>
|
148 |
+
/*
|
149 |
+
var result = await app.predict(
|
150 |
+
// "/predict", {"input_text":"input"}
|
151 |
+
"/chat",{"message":input}
|
152 |
+
|
153 |
+
)*/
|
154 |
+
// </PREDICT VERSION>
|
155 |
+
|
156 |
+
const submission = app.submit("/chat", { message: input })
|
157 |
+
|
158 |
+
for await (const msg of submission) {
|
159 |
+
if (msg.type === "data") {
|
160 |
+
console.log(msg.data);
|
161 |
+
console.log(msg);
|
162 |
+
_callback(msg)
|
163 |
+
}
|
164 |
+
|
165 |
+
if (msg.type === "status") {
|
166 |
+
console.log(msg);
|
167 |
+
}
|
168 |
+
}
|
169 |
+
return submission
|
170 |
+
|
171 |
+
//console.log(result)
|
172 |
+
//console.log("done in script")
|
173 |
+
//console.log(result)
|
174 |
+
//_callback((result))
|
175 |
+
//_callback(JSON.stringify(result))
|
176 |
+
//return result
|
177 |
+
//return app_info
|
178 |
+
//return "hello"
|
179 |
+
};
|
180 |
+
|
181 |
+
|
182 |
+
|
183 |
</script>
|
184 |
|
185 |
<script src="index.js"></script>
|
index.pck
CHANGED
Binary files a/index.pck and b/index.pck differ
|
|