Spaces:
Running
Running
update status code logic
Browse files
app.py
CHANGED
|
@@ -86,7 +86,7 @@ def predict(inputs, top_p, temperature, chat_counter, chatbot=[], history=[]):
|
|
| 86 |
history[-1] = partial_words
|
| 87 |
chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
|
| 88 |
token_counter+=1
|
| 89 |
-
yield chat, history, chat_counter # resembles {chatbot: chat, state: history}
|
| 90 |
|
| 91 |
|
| 92 |
def reset_textbox():
|
|
@@ -113,11 +113,16 @@ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
|
| 113 |
gr.HTML("""<h3 align="center">🔥This Huggingface Gradio Demo provides you full access to GPT4 API (4096 token limit). 🎉🥳🎉You don't need any OPENAI API key🙌</h1>""")
|
| 114 |
gr.HTML('''<center><a href="https://huggingface.co/spaces/ysharma/ChatGPT4?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>Duplicate the Space and run securely with your OpenAI API Key</center>''')
|
| 115 |
with gr.Column(elem_id = "col_container"):
|
|
|
|
| 116 |
#openai_api_key = gr.Textbox(type='password', label="Enter only your GPT4 OpenAI API key here")
|
| 117 |
chatbot = gr.Chatbot(elem_id='chatbot') #c
|
| 118 |
inputs = gr.Textbox(placeholder= "Hi there!", label= "Type an input and press Enter") #t
|
| 119 |
state = gr.State([]) #s
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
#inputs, top_p, temperature, top_k, repetition_penalty
|
| 123 |
with gr.Accordion("Parameters", open=False):
|
|
@@ -127,8 +132,8 @@ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
|
| 127 |
#repetition_penalty = gr.Slider( minimum=0.1, maximum=3.0, value=1.03, step=0.01, interactive=True, label="Repetition Penalty", )
|
| 128 |
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
| 129 |
|
| 130 |
-
inputs.submit( predict, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter],) #openai_api_key
|
| 131 |
-
b1.click( predict, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter],) #openai_api_key
|
| 132 |
b1.click(reset_textbox, [], [inputs])
|
| 133 |
inputs.submit(reset_textbox, [], [inputs])
|
| 134 |
|
|
|
|
| 86 |
history[-1] = partial_words
|
| 87 |
chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
|
| 88 |
token_counter+=1
|
| 89 |
+
yield chat, history, chat_counter, response # resembles {chatbot: chat, state: history}
|
| 90 |
|
| 91 |
|
| 92 |
def reset_textbox():
|
|
|
|
| 113 |
gr.HTML("""<h3 align="center">🔥This Huggingface Gradio Demo provides you full access to GPT4 API (4096 token limit). 🎉🥳🎉You don't need any OPENAI API key🙌</h1>""")
|
| 114 |
gr.HTML('''<center><a href="https://huggingface.co/spaces/ysharma/ChatGPT4?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>Duplicate the Space and run securely with your OpenAI API Key</center>''')
|
| 115 |
with gr.Column(elem_id = "col_container"):
|
| 116 |
+
#GPT4 API Key is provided by Huggingface
|
| 117 |
#openai_api_key = gr.Textbox(type='password', label="Enter only your GPT4 OpenAI API key here")
|
| 118 |
chatbot = gr.Chatbot(elem_id='chatbot') #c
|
| 119 |
inputs = gr.Textbox(placeholder= "Hi there!", label= "Type an input and press Enter") #t
|
| 120 |
state = gr.State([]) #s
|
| 121 |
+
with gr.Row():
|
| 122 |
+
with gr.Column(scale=7):
|
| 123 |
+
b1 = gr.Button()
|
| 124 |
+
with gr.Column(scale=3):
|
| 125 |
+
server_status_code = gr.Textbox(label="Status code from OpenAI server", )
|
| 126 |
|
| 127 |
#inputs, top_p, temperature, top_k, repetition_penalty
|
| 128 |
with gr.Accordion("Parameters", open=False):
|
|
|
|
| 132 |
#repetition_penalty = gr.Slider( minimum=0.1, maximum=3.0, value=1.03, step=0.01, interactive=True, label="Repetition Penalty", )
|
| 133 |
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
| 134 |
|
| 135 |
+
inputs.submit( predict, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter, server_status_code],) #openai_api_key
|
| 136 |
+
b1.click( predict, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter, server_status_code],) #openai_api_key
|
| 137 |
b1.click(reset_textbox, [], [inputs])
|
| 138 |
inputs.submit(reset_textbox, [], [inputs])
|
| 139 |
|