zhangjf commited on
Commit
21f1de2
1 Parent(s): fbd8943

write the app.py and upload data

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -122,23 +122,23 @@ thread.start()
122
  import gradio as gr
123
 
124
 
125
- def showcase(api_key):
126
- if not api_key==openai.api_key:
127
- chatbot_ret = [(f"Your entered api_key:<br>{api_key}<br>is incorrect.", f"So i cannot provide you any information in this private space.")]
128
  else:
129
  recent_qas = qas[:10]
130
- chatbot_ret = [(f"Your entered api_key is correct.", f"The latest {len(recent_qas)} query-responses are displayed below.")]
131
  for qa in recent_qas:
132
  chatbot_ret += [(qa["q"],qa["a"])]
133
  return chatbot_ret
134
 
135
 
136
- def download(api_key):
137
- if not api_key==openai.api_key:
138
- chatbot_ret = [(f"Your entered api_key:<br>{api_key}<br>is incorrect.", f"So i cannot provide you any information in this private space.")]
139
  file_ret = gr.File.update(value=None, visible=False)
140
  else:
141
- chatbot_ret = [(f"Your entered api_key is correct.", f"The file containing all processed query-responses ({len(qas)} in total) can be downloaded below.")]
142
  filename = f"qas-{len(qas)}.json"
143
  with open(filename, "w", encoding="utf-8") as f:
144
  f.write(json.dumps(qas, ensure_ascii=False, indent=2))
@@ -146,11 +146,11 @@ def download(api_key):
146
  return chatbot_ret, file_ret
147
 
148
 
149
- def display(api_key):
150
- if not api_key==openai.api_key:
151
- chatbot_ret = [(f"Your entered api_key:<br>{api_key}<br>is incorrect.", f"So i cannot provide you any information in this private space.")]
152
  elif len(qas)<1:
153
- chatbot_ret = [(f"Your entered api_key is correct.", f"But the progress has just started for a while and has no useful progress information to provide.")]
154
  else:
155
  time_takes = time.time() - start_time
156
  time_remains = time_takes * (len(qs)-len(qas)) / len(qas)
@@ -165,7 +165,7 @@ def display(api_key):
165
  dollars_tokens_processed = 0.002 * int(num_tokens_processed/1000)
166
  dollars_tokens_total = 0.002 * int(num_tokens_total/1000)
167
 
168
- chatbot_ret = [(f"Your entered api_key is correct.", f"The information of progress is displayed below.")]
169
  chatbot_ret += [(f"The number of processed / total queries:", f"{len(qas)} / {len(qs)}")]
170
  chatbot_ret += [(f"The hours already takes / est. remains:", f"{time_takes/3600:.2f} / {time_remains/3600:.2f}")]
171
  chatbot_ret += [(f"The time starts / est. ends:", f"{timestamp2string(start_time)} / {timestamp2string(end_time)}")]
@@ -179,7 +179,7 @@ with gr.Blocks() as demo:
179
 
180
  with gr.Column(variant="panel"):
181
  chatbot = gr.Chatbot()
182
- txt = gr.Textbox(show_label=False, placeholder="Enter my API_KEY to access this private space").style(container=False)
183
  with gr.Row():
184
  button_showcase = gr.Button("Show Recent Query-Responses")
185
  button_download = gr.Button("Download All Query-Responses")
 
122
  import gradio as gr
123
 
124
 
125
+ def showcase(access_key):
126
+ if not access_key==os.getenv('access_key'):
127
+ chatbot_ret = [(f"Your entered Access Key:<br>{access_key}<br>is incorrect.", f"So i cannot provide you any information in this private space.")]
128
  else:
129
  recent_qas = qas[:10]
130
+ chatbot_ret = [(f"Your entered Access Key is correct.", f"The latest {len(recent_qas)} query-responses are displayed below.")]
131
  for qa in recent_qas:
132
  chatbot_ret += [(qa["q"],qa["a"])]
133
  return chatbot_ret
134
 
135
 
136
+ def download(access_key):
137
+ if not access_key==os.getenv('access_key'):
138
+ chatbot_ret = [(f"Your entered Access Key:<br>{access_key}<br>is incorrect.", f"So i cannot provide you any information in this private space.")]
139
  file_ret = gr.File.update(value=None, visible=False)
140
  else:
141
+ chatbot_ret = [(f"Your entered Access Key is correct.", f"The file containing all processed query-responses ({len(qas)} in total) can be downloaded below.")]
142
  filename = f"qas-{len(qas)}.json"
143
  with open(filename, "w", encoding="utf-8") as f:
144
  f.write(json.dumps(qas, ensure_ascii=False, indent=2))
 
146
  return chatbot_ret, file_ret
147
 
148
 
149
+ def display(access_key):
150
+ if not access_key==os.getenv('access_key'):
151
+ chatbot_ret = [(f"Your entered Access Key:<br>{access_key}<br>is incorrect.", f"So i cannot provide you any information in this private space.")]
152
  elif len(qas)<1:
153
+ chatbot_ret = [(f"Your entered Access Key is correct.", f"But the progress has just started for a while and has no useful progress information to provide.")]
154
  else:
155
  time_takes = time.time() - start_time
156
  time_remains = time_takes * (len(qs)-len(qas)) / len(qas)
 
165
  dollars_tokens_processed = 0.002 * int(num_tokens_processed/1000)
166
  dollars_tokens_total = 0.002 * int(num_tokens_total/1000)
167
 
168
+ chatbot_ret = [(f"Your entered Access Key is correct.", f"The information of progress is displayed below.")]
169
  chatbot_ret += [(f"The number of processed / total queries:", f"{len(qas)} / {len(qs)}")]
170
  chatbot_ret += [(f"The hours already takes / est. remains:", f"{time_takes/3600:.2f} / {time_remains/3600:.2f}")]
171
  chatbot_ret += [(f"The time starts / est. ends:", f"{timestamp2string(start_time)} / {timestamp2string(end_time)}")]
 
179
 
180
  with gr.Column(variant="panel"):
181
  chatbot = gr.Chatbot()
182
+ txt = gr.Textbox(show_label=False, placeholder="Enter your Access Key to access this private space").style(container=False)
183
  with gr.Row():
184
  button_showcase = gr.Button("Show Recent Query-Responses")
185
  button_download = gr.Button("Download All Query-Responses")