Omnibus commited on
Commit
62bd81a
·
1 Parent(s): 1364611

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -5
app.py CHANGED
@@ -2,6 +2,11 @@ import gradio as gr
2
  import chatchain
3
  import crypt
4
  import os
 
 
 
 
 
5
  rec_list = []
6
  pa=os.environ['PASS']
7
 
@@ -75,15 +80,28 @@ with gr.Blocks() as app:
75
  'length': len(mychain_rec.chain)}
76
  message = f"Blockchain loaded from: {main_chain}{address}.json"
77
  #send_list,send_drop = update_send_list()
78
- rec_list,rec_drop = chatchain.update_rec_list(main_chain)
 
79
  #rec_drop = gr.Dropdown.update(label="Recipient", choices=[f for f in rec_list])
80
  return response,message,rec_drop
81
 
82
- def update_rec():
83
- _,rec_up = chatchain.update_rec_list(main_chain)
84
- return rec_up
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
- input_key.change(crypt.address,input_key,sender).then(update_rec,None,rec)
87
  pass_btn.click(checkp,pass_box,[invalid,valida])
88
 
89
  gen_wal_btn.click(crypt.generate_keys,None,[out2,out1,img3,out3,img1,img2]).then(create_new_chain,[out3,img1],[response_json,block_text,rec]).then(test_fn,[img1],[input_key])
 
2
  import chatchain
3
  import crypt
4
  import os
5
+ from huggingface_hub import (upload_file,HfApi)
6
+
7
+ token_self = os.environ['HF_TOKEN']
8
+ api = HfApi(token=token_self)
9
+
10
  rec_list = []
11
  pa=os.environ['PASS']
12
 
 
80
  'length': len(mychain_rec.chain)}
81
  message = f"Blockchain loaded from: {main_chain}{address}.json"
82
  #send_list,send_drop = update_send_list()
83
+
84
+ rec_list,rec_drop = update_rec_list()
85
  #rec_drop = gr.Dropdown.update(label="Recipient", choices=[f for f in rec_list])
86
  return response,message,rec_drop
87
 
88
+ def update_rec_list():
89
+ repo = main_chain.split('datasets/',1)[1].split('/raw',1)[0].split('/',1)[0]
90
+ name = main_chain.split('datasets/',1)[1].split('/raw',1)[0].split('/',1)[1]
91
+
92
+ f_ist = (api.list_repo_files(repo_id=f'{repo}/{name}', repo_type="dataset"))
93
+ rec_list =[]
94
+ for i,ea in enumerate(f_ist):
95
+ if "chat/" in ea:
96
+ try:
97
+ if not "__Source__" in ea:
98
+ rec_list.append(ea.split("/",1)[1].split("/",1)[0])
99
+ except Exception:
100
+ pass
101
+ return gr.Dropdown.update(label="Recipient", choices=[f for f in rec_list])
102
+ rec_list, rec_drop = update_rec_list()
103
 
104
+ input_key.change(crypt.address,input_key,sender).then(update_rec_list,None,rec)
105
  pass_btn.click(checkp,pass_box,[invalid,valida])
106
 
107
  gen_wal_btn.click(crypt.generate_keys,None,[out2,out1,img3,out3,img1,img2]).then(create_new_chain,[out3,img1],[response_json,block_text,rec]).then(test_fn,[img1],[input_key])