Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import json
|
4 |
import requests
|
|
|
|
|
5 |
|
6 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
7 |
|
@@ -12,29 +14,22 @@ def get_system_txt():
|
|
12 |
headers = {
|
13 |
"Authorization": f"Bearer {hf_token}"
|
14 |
}
|
15 |
-
|
|
|
|
|
16 |
if response.status_code == 200:
|
17 |
return response.text.strip()
|
18 |
else:
|
19 |
raise Exception("Failed to fetch system.txt from private Gradio space")
|
20 |
|
21 |
-
system_msg = get_system_txt()
|
22 |
-
|
23 |
-
def check_password(password):
|
24 |
-
if password == os.getenv("pw"):
|
25 |
-
return True
|
26 |
-
else:
|
27 |
-
return False
|
28 |
-
|
29 |
def predict(inputs, chat_counter, chatbot=[], history=[]):
|
30 |
headers = {
|
31 |
"Content-Type": "application/json",
|
32 |
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
33 |
}
|
34 |
|
35 |
-
#
|
36 |
-
|
37 |
-
system_msg = file.read().strip()
|
38 |
|
39 |
top_p = 1.0
|
40 |
temperature = 0.0
|
@@ -90,17 +85,13 @@ title = """<h1 align="center">Response simulator</h1>"""
|
|
90 |
with gr.Blocks() as demo:
|
91 |
gr.HTML(title)
|
92 |
with gr.Column(elem_id="col_container"):
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
server_status_code = gr.Textbox(label="Status code from OpenAI server",)
|
99 |
-
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
else:
|
104 |
-
gr.Text("Incorrect password. Please try again.")
|
105 |
|
106 |
-
demo.launch()
|
|
|
2 |
import os
|
3 |
import json
|
4 |
import requests
|
5 |
+
# from dotenv import load_dotenv
|
6 |
+
# load_dotenv()
|
7 |
|
8 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
9 |
|
|
|
14 |
headers = {
|
15 |
"Authorization": f"Bearer {hf_token}"
|
16 |
}
|
17 |
+
url = "https://huggingface.co/spaces/clayp/reaction-sys/resolve/main/system.txt"
|
18 |
+
response = requests.get(url, headers=headers)
|
19 |
+
|
20 |
if response.status_code == 200:
|
21 |
return response.text.strip()
|
22 |
else:
|
23 |
raise Exception("Failed to fetch system.txt from private Gradio space")
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
def predict(inputs, chat_counter, chatbot=[], history=[]):
|
26 |
headers = {
|
27 |
"Content-Type": "application/json",
|
28 |
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
29 |
}
|
30 |
|
31 |
+
# Get system message using get_system_txt function
|
32 |
+
system_msg = get_system_txt()
|
|
|
33 |
|
34 |
top_p = 1.0
|
35 |
temperature = 0.0
|
|
|
85 |
with gr.Blocks() as demo:
|
86 |
gr.HTML(title)
|
87 |
with gr.Column(elem_id="col_container"):
|
88 |
+
chatbot = gr.Chatbot(label='GPT-4', elem_id="chatbot")
|
89 |
+
inputs = gr.Textbox(placeholder="", label="Type an input and press Enter")
|
90 |
+
state = gr.State([])
|
91 |
+
server_status_code = gr.Textbox(label="Status code from OpenAI server",)
|
92 |
+
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
|
|
|
|
93 |
|
94 |
+
inputs.submit(predict, [inputs, chat_counter, chatbot, state], [chatbot, state, chat_counter, server_status_code], queue=True)
|
95 |
+
inputs.submit(reset_textbox, [], [inputs])
|
|
|
|
|
96 |
|
97 |
+
demo.queue(max_size=5, concurrency_count=5).launch()
|