Spaces:
Runtime error
Runtime error
update to layout and key
Browse files
app.py
CHANGED
@@ -7,9 +7,9 @@ import requests
|
|
7 |
API_URL = "https://api.openai.com/v1/chat/completions" #os.getenv("API_URL") + "/generate_stream"
|
8 |
|
9 |
#Testing with my Open AI Key
|
10 |
-
|
11 |
|
12 |
-
def predict(inputs, top_p, temperature,
|
13 |
|
14 |
payload = {
|
15 |
"model": "gpt-4",
|
@@ -24,7 +24,7 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
|
|
24 |
|
25 |
headers = {
|
26 |
"Content-Type": "application/json",
|
27 |
-
"Authorization": f"Bearer {
|
28 |
}
|
29 |
|
30 |
print(f"chat_counter - {chat_counter}")
|
@@ -110,9 +110,10 @@ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
|
110 |
#chatbot {height: 520px; overflow: auto;}""",
|
111 |
theme=theme) as demo:
|
112 |
gr.HTML(title)
|
|
|
113 |
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>''')
|
114 |
with gr.Column(elem_id = "col_container"):
|
115 |
-
openai_api_key = gr.Textbox(type='password', label="Enter only your GPT4 OpenAI API key here")
|
116 |
chatbot = gr.Chatbot(elem_id='chatbot') #c
|
117 |
inputs = gr.Textbox(placeholder= "Hi there!", label= "Type an input and press Enter") #t
|
118 |
state = gr.State([]) #s
|
@@ -126,8 +127,8 @@ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
|
126 |
#repetition_penalty = gr.Slider( minimum=0.1, maximum=3.0, value=1.03, step=0.01, interactive=True, label="Repetition Penalty", )
|
127 |
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
128 |
|
129 |
-
inputs.submit( predict, [inputs, top_p, temperature,
|
130 |
-
b1.click( predict, [inputs, top_p, temperature,
|
131 |
b1.click(reset_textbox, [], [inputs])
|
132 |
inputs.submit(reset_textbox, [], [inputs])
|
133 |
|
|
|
7 |
API_URL = "https://api.openai.com/v1/chat/completions" #os.getenv("API_URL") + "/generate_stream"
|
8 |
|
9 |
#Testing with my Open AI Key
|
10 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
11 |
|
12 |
+
def predict(inputs, top_p, temperature, chat_counter, chatbot=[], history=[]):
|
13 |
|
14 |
payload = {
|
15 |
"model": "gpt-4",
|
|
|
24 |
|
25 |
headers = {
|
26 |
"Content-Type": "application/json",
|
27 |
+
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
28 |
}
|
29 |
|
30 |
print(f"chat_counter - {chat_counter}")
|
|
|
110 |
#chatbot {height: 520px; overflow: auto;}""",
|
111 |
theme=theme) as demo:
|
112 |
gr.HTML(title)
|
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
|
|
|
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 |
|