Omnibus commited on
Commit
d0d78a3
·
verified ·
1 Parent(s): fbffc1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -16
app.py CHANGED
@@ -9,7 +9,7 @@ from huggingface_hub import InferenceClient,HfApi
9
  import random
10
  import json
11
  import datetime
12
- #from query import tasks
13
  from prompts import (
14
  FINDER,
15
  SAVE_MEMORY,
@@ -21,8 +21,10 @@ from prompts import (
21
  PREFIX,
22
  TASK_PROMPT,
23
  )
24
- api=HfApi()
25
-
 
 
26
 
27
 
28
  client = InferenceClient(
@@ -168,6 +170,7 @@ def compress_data(c,purpose, task, history, result):
168
 
169
 
170
  def save_memory(purpose, history):
 
171
  history=str(history)
172
  c=0
173
  inp = str(history)
@@ -217,25 +220,31 @@ def save_memory(purpose, history):
217
  e=e+chunk
218
  s=s+chunk
219
  print ("final1" + resp)
220
-
221
- #lines = resp.strip().strip("\n").split("\n")
222
- skills=[]
223
- #skill_dict={}
224
- #for i,line in enumerate(lines):
225
- # print(f'Line:: {line}')
226
- #skills.append(resp)
227
- #print ("final2" + resp)
228
  try:
229
  resp=resp.split('</s>')[0]
230
  print ("final2" + resp)
231
  except Exception as e:
232
  resp = resp
233
  print(e)
234
-
235
- skills.append(resp)
236
- out=skills
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  #history = "result: {}\n".format(resp)
238
- return out
239
 
240
 
241
 
@@ -488,7 +497,7 @@ with gr.Blocks() as app:
488
  #go=button.click(check_rand,[rand,seed],seed).then(run,[opt,chatbot,tokens,char_stats,seed],[chatbot,char_stats,json_out,opt])
489
  go=button.click(check_rand,[rand,seed],seed).then(run,[opt,chatbot],[chatbot])
490
  stop_button.click(None,None,None,cancels=[go])
491
- app.launch(show_api=False)
492
 
493
 
494
 
 
9
  import random
10
  import json
11
  import datetime
12
+ import uuid
13
  from prompts import (
14
  FINDER,
15
  SAVE_MEMORY,
 
21
  PREFIX,
22
  TASK_PROMPT,
23
  )
24
+ reponame="Omnibus/tmp"
25
+ save_data=f'https://huggingface.co/datasets/{reponame}/raw/main/'
26
+ token_self = os.environ['HF_TOKEN']
27
+ api=HfApi(token=token_self)
28
 
29
 
30
  client = InferenceClient(
 
170
 
171
 
172
  def save_memory(purpose, history):
173
+ uid=uuid.uuid4()
174
  history=str(history)
175
  c=0
176
  inp = str(history)
 
220
  e=e+chunk
221
  s=s+chunk
222
  print ("final1" + resp)
 
 
 
 
 
 
 
 
223
  try:
224
  resp=resp.split('</s>')[0]
225
  print ("final2" + resp)
226
  except Exception as e:
227
  resp = resp
228
  print(e)
229
+ timestamp=str(datetime.datetime.now())
230
+ timename=timestamp.replace(" ","--").replace(":","-").replace(".","-")
231
+ json_object=[resp]
232
+ #json_object = json.dumps(out_box)
233
+ #json_object = json.dumps(out_box,indent=4)
234
+ with open("tmp1.json", "w") as outfile:
235
+ outfile.write(json_object)
236
+ api.upload_file(
237
+ path_or_fileobj=f"tmp-{uid}.json",
238
+ path_in_repo=f"/mem-test/{timename}.json",
239
+ repo_id=reponame,
240
+ #repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
241
+ token=token_self,
242
+ repo_type="dataset",
243
+ )
244
+ #skills.append(resp)
245
+ #out=skills
246
  #history = "result: {}\n".format(resp)
247
+ return [resp]
248
 
249
 
250
 
 
497
  #go=button.click(check_rand,[rand,seed],seed).then(run,[opt,chatbot,tokens,char_stats,seed],[chatbot,char_stats,json_out,opt])
498
  go=button.click(check_rand,[rand,seed],seed).then(run,[opt,chatbot],[chatbot])
499
  stop_button.click(None,None,None,cancels=[go])
500
+ app.queue(default_concurrency_limit=20).launch(show_api=False)
501
 
502
 
503