clayp commited on
Commit
857ad2f
·
1 Parent(s): e09bdd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -24
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
- response = requests.get(f"https://huggingface.co/spaces/clayp/reaction-sys/resolve/main/system.txt", headers=headers)
 
 
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
- # Read system message from system.txt
36
- with open("system.txt", "r") as file:
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
- password_input = gr.inputs.Password(label="Enter password to access the app")
94
- if check_password(password_input):
95
- chatbot = gr.Chatbot(label='GPT-4', elem_id="chatbot")
96
- inputs = gr.Textbox(placeholder="", label="Type an input and press Enter")
97
- state = gr.State([])
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
- inputs.submit(predict, [inputs, chat_counter, chatbot, state], [chatbot, state, chat_counter, server_status_code],)
102
- inputs.submit(reset_textbox, [], [inputs])
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()