RamAnanth1 commited on
Commit
85df983
·
1 Parent(s): e69cdea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -94
app.py CHANGED
@@ -31,104 +31,12 @@ def chat(message, chat_history):
31
  logger.info(f"out_chat_: {len(out_chat)}")
32
  return out_chat, chat_history
33
 
34
- start_work = """async() => {
35
- function isMobile() {
36
- try {
37
- document.createEvent("TouchEvent"); return true;
38
- } catch(e) {
39
- return false;
40
- }
41
- }
42
- function getClientHeight()
43
- {
44
- var clientHeight=0;
45
- if(document.body.clientHeight&&document.documentElement.clientHeight) {
46
- var clientHeight = (document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
47
- } else {
48
- var clientHeight = (document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
49
- }
50
- return clientHeight;
51
- }
52
-
53
- function setNativeValue(element, value) {
54
- const valueSetter = Object.getOwnPropertyDescriptor(element.__proto__, 'value').set;
55
- const prototype = Object.getPrototypeOf(element);
56
- const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set;
57
-
58
- if (valueSetter && valueSetter !== prototypeValueSetter) {
59
- prototypeValueSetter.call(element, value);
60
- } else {
61
- valueSetter.call(element, value);
62
- }
63
- }
64
- var gradioEl = document.querySelector('body > gradio-app').shadowRoot;
65
- if (!gradioEl) {
66
- gradioEl = document.querySelector('body > gradio-app');
67
- }
68
-
69
- if (typeof window['gradioEl'] === 'undefined') {
70
- window['gradioEl'] = gradioEl;
71
-
72
- const page1 = window['gradioEl'].querySelectorAll('#page_1')[0];
73
- const page2 = window['gradioEl'].querySelectorAll('#page_2')[0];
74
-
75
- page1.style.display = "none";
76
- page2.style.display = "block";
77
-
78
- window['div_count'] = 0;
79
- window['chat_bot'] = window['gradioEl'].querySelectorAll('#chat_bot')[0];
80
- window['chat_bot1'] = window['gradioEl'].querySelectorAll('#chat_bot1')[0];
81
- chat_row = window['gradioEl'].querySelectorAll('#chat_row')[0];
82
- prompt_row = window['gradioEl'].querySelectorAll('#prompt_row')[0];
83
- window['chat_bot1'].children[1].textContent = '';
84
-
85
- clientHeight = getClientHeight();
86
- new_height = (clientHeight-300) + 'px';
87
- chat_row.style.height = new_height;
88
- window['chat_bot'].style.height = new_height;
89
- window['chat_bot'].children[2].style.height = new_height;
90
- window['chat_bot1'].style.height = new_height;
91
- window['chat_bot1'].children[2].style.height = new_height;
92
- prompt_row.children[0].style.flex = 'auto';
93
- prompt_row.children[0].style.width = '100%';
94
-
95
- window['checkChange'] = function checkChange() {
96
- try {
97
- if (window['chat_bot'].children[2].children[0].children.length > window['div_count']) {
98
- new_len = window['chat_bot'].children[2].children[0].children.length - window['div_count'];
99
- for (var i = 0; i < new_len; i++) {
100
- new_div = window['chat_bot'].children[2].children[0].children[window['div_count'] + i].cloneNode(true);
101
- window['chat_bot1'].children[2].children[0].appendChild(new_div);
102
- }
103
- window['div_count'] = chat_bot.children[2].children[0].children.length;
104
- }
105
- if (window['chat_bot'].children[0].children.length > 1) {
106
- window['chat_bot1'].children[1].textContent = window['chat_bot'].children[0].children[1].textContent;
107
- } else {
108
- window['chat_bot1'].children[1].textContent = '';
109
- }
110
-
111
- } catch(e) {
112
- }
113
- }
114
- window['checkChange_interval'] = window.setInterval("window.checkChange()", 500);
115
- }
116
-
117
- return false;
118
- }"""
119
 
120
 
121
  with gr.Blocks(title='Talk to chatGPT') as demo:
122
  gr.Markdown("## Talk to chatGPT with your voice in your native language ! ##")
123
- gr.HTML("<p>You can duplicate this space and use your own session token: <a style='display:inline-block' href='https://huggingface.co/spaces/yizhangliu/chatGPT?duplicate=true'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14' alt='Duplicate Space'></a></p>")
124
- gr.HTML("<p> Instruction on how to get session token can be seen in video <a style='display:inline-block' href='https://www.youtube.com/watch?v=TdNSj_qgdFk'><font style='color:blue;weight:bold;'>here</font></a>. Add your session token by going to settings and add under secrets. </p>")
125
- with gr.Group(elem_id="page_1", visible=True) as page_1:
126
- with gr.Box():
127
- with gr.Row():
128
- start_button = gr.Button("Let's talk to chatGPT!", elem_id="start-btn", visible=True)
129
- start_button.click(fn=None, inputs=[], outputs=[], _js=start_work)
130
-
131
- with gr.Group(elem_id="page_2", visible=False) as page_2:
132
  with gr.Row(elem_id="chat_row"):
133
  chatbot = gr.Chatbot(elem_id="chat_bot", visible=False).style(color_map=("green", "blue"))
134
  chatbot1 = gr.Chatbot(elem_id="chat_bot1").style(color_map=("green", "blue"))
 
31
  logger.info(f"out_chat_: {len(out_chat)}")
32
  return out_chat, chat_history
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
 
36
  with gr.Blocks(title='Talk to chatGPT') as demo:
37
  gr.Markdown("## Talk to chatGPT with your voice in your native language ! ##")
38
+
39
+ with gr.Group(elem_id="page_2") as page_2:
 
 
 
 
 
 
 
40
  with gr.Row(elem_id="chat_row"):
41
  chatbot = gr.Chatbot(elem_id="chat_bot", visible=False).style(color_map=("green", "blue"))
42
  chatbot1 = gr.Chatbot(elem_id="chat_bot1").style(color_map=("green", "blue"))