Spaces:
Runtime error
Runtime error
yizhangliu
commited on
Commit
•
25a5a47
1
Parent(s):
ea13408
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from loguru import logger
|
|
5 |
import random
|
6 |
|
7 |
session_token = os.environ.get('SessionToken')
|
8 |
-
logger.info(f"session_token_: {session_token}")
|
9 |
|
10 |
def get_response_from_chatbot(text):
|
11 |
try:
|
@@ -29,9 +29,82 @@ def chat(message, chat_history):
|
|
29 |
chat_history = json.dumps(out_chat)
|
30 |
# print(f'chat_2_{chat_history}')
|
31 |
return out_chat, chat_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
with gr.Blocks(title='chat with chatgpt') as demo:
|
34 |
with gr.Group(elem_id="page_1", visible=True) as page_1:
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
with gr.Row(elem_id="prompt_row"):
|
36 |
chatbot = gr.Chatbot(elem_id="chat_bot").style(color_map=("green", "blue"))
|
37 |
chatbot1 = gr.Chatbot(elem_id="chat_bot1").style(color_map=("green", "blue"))
|
|
|
5 |
import random
|
6 |
|
7 |
session_token = os.environ.get('SessionToken')
|
8 |
+
# logger.info(f"session_token_: {session_token}")
|
9 |
|
10 |
def get_response_from_chatbot(text):
|
11 |
try:
|
|
|
29 |
chat_history = json.dumps(out_chat)
|
30 |
# print(f'chat_2_{chat_history}')
|
31 |
return out_chat, chat_history
|
32 |
+
|
33 |
+
start_work = """async() => {
|
34 |
+
function isMobile() {
|
35 |
+
try {
|
36 |
+
document.createEvent("TouchEvent"); return true;
|
37 |
+
} catch(e) {
|
38 |
+
return false;
|
39 |
+
}
|
40 |
+
}
|
41 |
+
function getClientHeight()
|
42 |
+
{
|
43 |
+
var clientHeight=0;
|
44 |
+
if(document.body.clientHeight&&document.documentElement.clientHeight) {
|
45 |
+
var clientHeight = (document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
|
46 |
+
} else {
|
47 |
+
var clientHeight = (document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
|
48 |
+
}
|
49 |
+
return clientHeight;
|
50 |
+
}
|
51 |
+
|
52 |
+
function setNativeValue(element, value) {
|
53 |
+
const valueSetter = Object.getOwnPropertyDescriptor(element.__proto__, 'value').set;
|
54 |
+
const prototype = Object.getPrototypeOf(element);
|
55 |
+
const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set;
|
56 |
+
|
57 |
+
if (valueSetter && valueSetter !== prototypeValueSetter) {
|
58 |
+
prototypeValueSetter.call(element, value);
|
59 |
+
} else {
|
60 |
+
valueSetter.call(element, value);
|
61 |
+
}
|
62 |
+
}
|
63 |
+
var gradioEl = document.querySelector('body > gradio-app').shadowRoot;
|
64 |
+
if (!gradioEl) {
|
65 |
+
gradioEl = document.querySelector('body > gradio-app');
|
66 |
+
}
|
67 |
+
|
68 |
+
if (typeof window['gradioEl'] === 'undefined') {
|
69 |
+
window['gradioEl'] = gradioEl;
|
70 |
+
|
71 |
+
const page1 = window['gradioEl'].querySelectorAll('#page_1')[0];
|
72 |
+
const page2 = window['gradioEl'].querySelectorAll('#page_2')[0];
|
73 |
|
74 |
+
page1.style.display = "none";
|
75 |
+
page2.style.display = "block";
|
76 |
+
|
77 |
+
window['div_count'] = 0;
|
78 |
+
window['checkChange'] = function checkChange() {
|
79 |
+
try {
|
80 |
+
chat_bot = window['gradioEl'].querySelectorAll('#chat_bot')[0];
|
81 |
+
chat_bot1 = window['gradioEl'].querySelectorAll('#chat_bot1')[0];
|
82 |
+
if (chat_bot.children[2].children[0].children.length > window['div_count']) {
|
83 |
+
new_len = chat_bot.children[2].children[0].children.length - window['div_count'];
|
84 |
+
for (var i = 0; i < new_len; i++) {
|
85 |
+
new_div = chat_bot.children[2].children[0].children[window['div_count'] + i].cloneNode(true);
|
86 |
+
chat_bot1.children[2].children[0].appendChild(new_div);
|
87 |
+
}
|
88 |
+
window['div_count'] = chat_bot.children[2].children[0].children.length;
|
89 |
+
}
|
90 |
+
} catch(e) {
|
91 |
+
}
|
92 |
+
}
|
93 |
+
window['checkChange_interval'] = window.setInterval("window.checkChange()", 500);
|
94 |
+
}
|
95 |
+
|
96 |
+
return false;
|
97 |
+
}"""
|
98 |
+
|
99 |
+
|
100 |
with gr.Blocks(title='chat with chatgpt') as demo:
|
101 |
with gr.Group(elem_id="page_1", visible=True) as page_1:
|
102 |
+
with gr.Box():
|
103 |
+
with gr.Row():
|
104 |
+
start_button = gr.Button("Let's GO!", elem_id="start-btn", visible=True)
|
105 |
+
start_button.click(fn=None, inputs=[], outputs=[], _js=start_work)
|
106 |
+
|
107 |
+
with gr.Group(elem_id="page_2", visible=False) as page_2:
|
108 |
with gr.Row(elem_id="prompt_row"):
|
109 |
chatbot = gr.Chatbot(elem_id="chat_bot").style(color_map=("green", "blue"))
|
110 |
chatbot1 = gr.Chatbot(elem_id="chat_bot1").style(color_map=("green", "blue"))
|