Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,40 +4,83 @@ import crypt
|
|
4 |
import os
|
5 |
from huggingface_hub import (upload_file,HfApi)
|
6 |
|
7 |
-
|
8 |
-
api = HfApi(token=token_self)
|
9 |
-
global rec_list
|
10 |
rec_list = []
|
11 |
pa=os.environ['PASS']
|
12 |
|
13 |
main_chain='https://huggingface.co/datasets/Omnibus/chat-at/raw/main/chat/'
|
14 |
|
15 |
-
#rec_list,_ = chatchain.update_rec_list(main_chain)
|
16 |
-
def update_rec_list():
|
17 |
-
repo = main_chain.split('datasets/',1)[1].split('/raw',1)[0].split('/',1)[0]
|
18 |
-
name = main_chain.split('datasets/',1)[1].split('/raw',1)[0].split('/',1)[1]
|
19 |
-
f_ist = (api.list_repo_files(repo_id=f'{repo}/{name}', repo_type="dataset"))
|
20 |
-
rec_list.clear()
|
21 |
-
rec_list =[]
|
22 |
-
for i,ea in enumerate(f_ist):
|
23 |
-
if "chat/" in ea:
|
24 |
-
try:
|
25 |
-
if not "__Source__" in ea:
|
26 |
-
rec_list.append(ea.split("/",1)[1].split("/",1)[0])
|
27 |
-
except Exception:
|
28 |
-
pass
|
29 |
-
return rec_list, gr.Dropdown(label="Recipient", choices=[f for f in rec_list])
|
30 |
rec_list, rec_drop = chatchain.update_rec_list(main_chain)
|
31 |
|
32 |
-
def up_rec():
|
33 |
-
rec_list,rec_drop = update_rec_list()
|
34 |
-
return gr.Dropdown(label="Recipient", choices=[f for f in rec_list])
|
35 |
def checkp(inp):
|
36 |
if inp == pa:
|
37 |
return gr.update(visible=False), gr.update(visible=True)
|
38 |
elif inp != pa:
|
39 |
return gr.update(visible=True), gr.update(visible=False)
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
with gr.Blocks() as app:
|
42 |
with gr.Row(visible=True) as invalid:
|
43 |
pass_box = gr.Textbox()
|
@@ -103,6 +146,7 @@ with gr.Blocks() as app:
|
|
103 |
#rec_drop = gr.Dropdown.update(label="Recipient", choices=[f for f in rec_list])
|
104 |
return response,message,rec_drop
|
105 |
|
|
|
106 |
|
107 |
|
108 |
input_key.change(crypt.address,input_key,sender).then(chatchain.update_rec_list,None,rec)
|
|
|
4 |
import os
|
5 |
from huggingface_hub import (upload_file,HfApi)
|
6 |
|
7 |
+
|
|
|
|
|
8 |
rec_list = []
|
9 |
pa=os.environ['PASS']
|
10 |
|
11 |
main_chain='https://huggingface.co/datasets/Omnibus/chat-at/raw/main/chat/'
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
rec_list, rec_drop = chatchain.update_rec_list(main_chain)
|
14 |
|
|
|
|
|
|
|
15 |
def checkp(inp):
|
16 |
if inp == pa:
|
17 |
return gr.update(visible=False), gr.update(visible=True)
|
18 |
elif inp != pa:
|
19 |
return gr.update(visible=True), gr.update(visible=False)
|
20 |
|
21 |
+
|
22 |
+
############################################
|
23 |
+
def send_message(send,rec,message):
|
24 |
+
response_send={}
|
25 |
+
response_rec={}
|
26 |
+
show_chain_send={}
|
27 |
+
show_chain_rec={}
|
28 |
+
data_send=None
|
29 |
+
data_rec=None
|
30 |
+
rec_send=None
|
31 |
+
rec_drop=None
|
32 |
+
message_send=None
|
33 |
+
message_rec=None
|
34 |
+
trans_data=None
|
35 |
+
trans_mes=None
|
36 |
+
balance_send = 0
|
37 |
+
balance_rec = 0
|
38 |
+
mes = "blank message"
|
39 |
+
try:
|
40 |
+
response,message = get_my_chain_send(send)
|
41 |
+
send_rec = response
|
42 |
+
response,message = get_my_chain_rec(rec)
|
43 |
+
lod_rec = response
|
44 |
+
mes1,val,mes2,ind = valid_rec()
|
45 |
+
print (f'val:: {val}')
|
46 |
+
if val == False:
|
47 |
+
p=False
|
48 |
+
mes = f"Recipient: {rec} Blockchain is not valid. {mes2} at Index {ind}"
|
49 |
+
print(mes)
|
50 |
+
p=True
|
51 |
+
#if z==False:
|
52 |
+
# mes = b_mes
|
53 |
+
# p=False
|
54 |
+
except Exception as e:
|
55 |
+
mes = f"An Error Occured: {e}"
|
56 |
+
p=False
|
57 |
+
print (mes)
|
58 |
+
|
59 |
+
if p==False:
|
60 |
+
return (mes, p,None,None,None,None,None,None,None,None,None,None,None)
|
61 |
+
if p==True:
|
62 |
+
chatchain.mychain_send.new_transaction(f"{send}",f"{rec}",f"{amount}")
|
63 |
+
message_send = "Transaction Added to Pool"
|
64 |
+
data_send = pd.DataFrame(chatchain.mychain_send.pending_transactions)
|
65 |
+
chatchain.mychain_rec.new_transaction(f"{send}",f"{rec}",f"{amount}")
|
66 |
+
message_rec = "Transaction Added to Pool"
|
67 |
+
data_rec = pd.DataFrame(chatchain.mychain_rec.pending_transactions)
|
68 |
+
response_send, show_chain_send, message_send = mychain_mine_block_send(chain_r=None,chain_n=send)
|
69 |
+
|
70 |
+
#mychain_mine_block_trans(balance_send, chain_r=None,chain_n=send)
|
71 |
+
|
72 |
+
response_rec, show_chain_rec, message_rec = mychain_mine_block_rec(chain_r=None,chain_n=rec)
|
73 |
+
mes = (f'Send: {message_send} :: Recieve: {message_rec}')
|
74 |
+
_,rec_send=update_send_list()
|
75 |
+
_,rec_drop=update_rec_list()
|
76 |
+
#trans_bx = merge_trans()
|
77 |
+
#trans_data, mes = bc_utils.bc_transactions(trans_bx)
|
78 |
+
return (mes, p, response_send, response_rec, show_chain_send, show_chain_rec, data_send, data_rec, message_send, message_rec, rec_send, rec_drop)
|
79 |
+
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
|
84 |
with gr.Blocks() as app:
|
85 |
with gr.Row(visible=True) as invalid:
|
86 |
pass_box = gr.Textbox()
|
|
|
146 |
#rec_drop = gr.Dropdown.update(label="Recipient", choices=[f for f in rec_list])
|
147 |
return response,message,rec_drop
|
148 |
|
149 |
+
send_mes.click(send_message,[sender,rec,send_mes],[block_text,out_box_bool,json_out_send,json_out_rec,chain_json_send,chain_json_rec,trans_data_send,trans_data_rec,block_text_send,block_text_rec,send,rec,trans_data])
|
150 |
|
151 |
|
152 |
input_key.change(crypt.address,input_key,sender).then(chatchain.update_rec_list,None,rec)
|