zhangjf commited on
Commit
e3788ae
1 Parent(s): 7fb1b6e

write the app.py and upload data

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -2,6 +2,7 @@ import openai
2
  import tiktoken
3
 
4
  import collections
 
5
  import datetime
6
  import time
7
  import pytz
@@ -33,11 +34,12 @@ def num_tokens_from_messages(messages, model="gpt-3.5-turbo"):
33
  raise NotImplementedError(f"""num_tokens_from_messages() is not presently implemented for model {model}.
34
  See https://github.com/openai/openai-python/blob/main/chatml.md for information on how messages are converted to tokens.""")
35
 
 
36
  qas = []
37
  qs = []
38
  start_time = None
39
 
40
- def read_qs():
41
  directory = "./dialogues_set"
42
  filenames = [
43
  'dialogues_film.json',
@@ -92,8 +94,8 @@ def ask(query, max_attempt_times=3):
92
  return answer
93
 
94
 
95
- def askingChatGPT(min_interval_seconds=10):
96
- qs = read_qs()
97
 
98
  start_time = time.time()
99
  for i, q in enumerate(qs):
@@ -113,7 +115,7 @@ def askingChatGPT(min_interval_seconds=10):
113
  return
114
 
115
 
116
- thread = threading.Thread(target=my_function)
117
  thread.daemon = True
118
  thread.start()
119
 
@@ -138,7 +140,7 @@ def download(api_key):
138
  file_ret = gr.File.update(value=None, visible=False)
139
  else:
140
  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.")]
141
- filename = f"qas{len(qas)}.json"
142
  with open(filename, "w", encoding="utf-8") as f:
143
  f.write(json.dumps(qas, ensure_ascii=False, indent=2))
144
  file_ret = gr.File.update(value=filename, visible=True)
 
2
  import tiktoken
3
 
4
  import collections
5
+ import threading
6
  import datetime
7
  import time
8
  import pytz
 
34
  raise NotImplementedError(f"""num_tokens_from_messages() is not presently implemented for model {model}.
35
  See https://github.com/openai/openai-python/blob/main/chatml.md for information on how messages are converted to tokens.""")
36
 
37
+
38
  qas = []
39
  qs = []
40
  start_time = None
41
 
42
+ def read_qs(qs, qas):
43
  directory = "./dialogues_set"
44
  filenames = [
45
  'dialogues_film.json',
 
94
  return answer
95
 
96
 
97
+ def askingChatGPT(qs, qas, min_interval_seconds=10):
98
+ read_qs(qs, qas)
99
 
100
  start_time = time.time()
101
  for i, q in enumerate(qs):
 
115
  return
116
 
117
 
118
+ thread = threading.Thread(target=lambda :askingChatGPT(qs, qas))
119
  thread.daemon = True
120
  thread.start()
121
 
 
140
  file_ret = gr.File.update(value=None, visible=False)
141
  else:
142
  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.")]
143
+ filename = f"qas-{len(qas)}.json"
144
  with open(filename, "w", encoding="utf-8") as f:
145
  f.write(json.dumps(qas, ensure_ascii=False, indent=2))
146
  file_ret = gr.File.update(value=filename, visible=True)