Spaces:
Runtime error
Runtime error
yizhangliu
commited on
Commit
•
afccef1
1
Parent(s):
ef59e17
Update app.py
Browse files
app.py
CHANGED
@@ -25,13 +25,116 @@ def chat(message, history):
|
|
25 |
history.append((message, response))
|
26 |
return history, history
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
demo.launch(debug = True)
|
|
|
25 |
history.append((message, response))
|
26 |
return history, history
|
27 |
|
28 |
+
start_work = """async() => {
|
29 |
+
function isMobile() {
|
30 |
+
try {
|
31 |
+
document.createEvent("TouchEvent"); return true;
|
32 |
+
} catch(e) {
|
33 |
+
return false;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
function getClientHeight()
|
37 |
+
{
|
38 |
+
var clientHeight=0;
|
39 |
+
if(document.body.clientHeight&&document.documentElement.clientHeight) {
|
40 |
+
var clientHeight = (document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
|
41 |
+
} else {
|
42 |
+
var clientHeight = (document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
|
43 |
+
}
|
44 |
+
return clientHeight;
|
45 |
+
}
|
46 |
+
|
47 |
+
function setNativeValue(element, value) {
|
48 |
+
const valueSetter = Object.getOwnPropertyDescriptor(element.__proto__, 'value').set;
|
49 |
+
const prototype = Object.getPrototypeOf(element);
|
50 |
+
const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set;
|
51 |
+
|
52 |
+
if (valueSetter && valueSetter !== prototypeValueSetter) {
|
53 |
+
prototypeValueSetter.call(element, value);
|
54 |
+
} else {
|
55 |
+
valueSetter.call(element, value);
|
56 |
+
}
|
57 |
+
}
|
58 |
+
var gradioEl = document.querySelector('body > gradio-app').shadowRoot;
|
59 |
+
if (!gradioEl) {
|
60 |
+
gradioEl = document.querySelector('body > gradio-app');
|
61 |
+
}
|
62 |
+
|
63 |
+
if (typeof window['gradioEl'] === 'undefined') {
|
64 |
+
window['gradioEl'] = gradioEl;
|
65 |
+
|
66 |
+
tabitems = window['gradioEl'].querySelectorAll('.tabitem');
|
67 |
+
for (var i = 0; i < tabitems.length; i++) {
|
68 |
+
tabitems[i].childNodes[0].children[0].style.display='none';
|
69 |
+
tabitems[i].childNodes[0].children[1].children[0].style.display='none';
|
70 |
+
tabitems[i].childNodes[0].children[1].children[1].children[0].children[1].style.display="none";
|
71 |
+
}
|
72 |
+
tab_demo = window['gradioEl'].querySelectorAll('#tab_demo')[0];
|
73 |
+
tab_demo.style.display = "block";
|
74 |
+
tab_demo.setAttribute('style', 'height: 100%;');
|
75 |
+
const page1 = window['gradioEl'].querySelectorAll('#page_1')[0];
|
76 |
+
const page2 = window['gradioEl'].querySelectorAll('#page_2')[0];
|
77 |
+
|
78 |
+
page1.style.display = "none";
|
79 |
+
page2.style.display = "block";
|
80 |
+
# window['prevPrompt'] = '';
|
81 |
+
# window['doCheckPrompt'] = 0;
|
82 |
+
# window['checkPrompt'] = function checkPrompt() {
|
83 |
+
# try {
|
84 |
+
# texts = window['gradioEl'].querySelectorAll('textarea');
|
85 |
+
# text0 = texts[0];
|
86 |
+
# text1 = texts[1];
|
87 |
+
# if (window['doCheckPrompt'] === 0 && window['prevPrompt'] !== text1.value) {
|
88 |
+
# console.log('_____new prompt___[' + text1.value + ']_');
|
89 |
+
# window['doCheckPrompt'] = 1;
|
90 |
+
# window['prevPrompt'] = text1.value;
|
91 |
+
# for (var i = 2; i < texts.length; i++) {
|
92 |
+
# setNativeValue(texts[i], text1.value);
|
93 |
+
# texts[i].dispatchEvent(new Event('input', { bubbles: true }));
|
94 |
+
# }
|
95 |
+
# setTimeout(function() {
|
96 |
+
# btns = window['gradioEl'].querySelectorAll('button');
|
97 |
+
# for (var i = 0; i < btns.length; i++) {
|
98 |
+
# if (btns[i].innerText == 'Submit') {
|
99 |
+
# btns[i].click();
|
100 |
+
# }
|
101 |
+
# }
|
102 |
+
# window['doCheckPrompt'] = 0;
|
103 |
+
# }, 10);
|
104 |
+
# }
|
105 |
+
# } catch(e) {
|
106 |
+
# }
|
107 |
+
# }
|
108 |
+
# window['checkPrompt_interval'] = window.setInterval("window.checkPrompt()", 100);
|
109 |
+
# }
|
110 |
+
|
111 |
+
return false;
|
112 |
+
}"""
|
113 |
+
|
114 |
+
with gr.Blocks(title='Text to Image') as demo:
|
115 |
+
with gr.Group(elem_id="page_1", visible=True) as page_1:
|
116 |
+
with gr.Box():
|
117 |
+
with gr.Row():
|
118 |
+
start_button = gr.Button("Let's GO!", elem_id="start-btn", visible=True)
|
119 |
+
start_button.click(fn=None, inputs=[], outputs=[], _js=start_work)
|
120 |
+
|
121 |
+
with gr.Group(elem_id="page_2", visible=False) as page_2:
|
122 |
+
chatbot = gr.Chatbot(elem_id="chat_bot").style(color_map=("green", "gray"))
|
123 |
+
demo = gr.Interface(
|
124 |
+
chat,
|
125 |
+
["text", "state"],
|
126 |
+
[chatbot, "state"],
|
127 |
+
allow_flagging="never",
|
128 |
+
show_label=False,
|
129 |
+
)
|
130 |
+
|
131 |
+
# chatbot = gr.Chatbot().style(color_map=("green", "gray"))
|
132 |
+
# demo = gr.Interface(
|
133 |
+
# chat,
|
134 |
+
# ["text", "state"],
|
135 |
+
# [chatbot, "state"],
|
136 |
+
# allow_flagging="never",
|
137 |
+
# show_label=False,
|
138 |
+
# )
|
139 |
|
140 |
demo.launch(debug = True)
|