File size: 6,801 Bytes
785022a
089bad2
49d4a4b
d9650af
62bd81a
 
b81d2c3
9e5632d
d9650af
785022a
089bad2
a656504
a364a23
a656504
d9650af
 
 
 
 
785022a
b81d2c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54f26dc
b81d2c3
54f26dc
b81d2c3
ffb9979
b81d2c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54f26dc
b81d2c3
 
 
54f26dc
b81d2c3
 
 
 
 
54f26dc
b81d2c3
 
 
 
 
785022a
d9650af
 
 
 
842bf1d
9fde426
 
785022a
9fde426
 
 
 
 
 
0425e00
a9c4c7d
9fde426
 
089bad2
 
 
 
9fde426
 
 
 
 
 
 
 
5a53979
9fde426
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d5df1b
 
9fde426
 
 
65340ce
089bad2
65340ce
ff16456
089bad2
 
 
 
62bd81a
a364a23
4cb6097
7ceaf08
12790ec
 
 
54f26dc
94df3c5
7ceaf08
12790ec
33a841b
49d4a4b
65340ce
3dece81
49d4a4b
 
785022a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import gradio as gr
import chatchain
import crypt
import os
from huggingface_hub import (upload_file,HfApi)


rec_list = []
pa=os.environ['PASS']

main_chain='https://huggingface.co/datasets/Omnibus/chat-at/raw/main/chat/'

rec_list, rec_drop = chatchain.update_rec_list(main_chain)

def checkp(inp):
    if inp == pa:
        return gr.update(visible=False), gr.update(visible=True)
    elif inp != pa:
        return gr.update(visible=True), gr.update(visible=False)


############################################
def send_message(send,rec,message):
    response_send={}
    response_rec={}
    show_chain_send={}
    show_chain_rec={}
    data_send=None
    data_rec=None
    rec_send=None
    rec_drop=None
    message_send=None
    message_rec=None    
    trans_data=None
    trans_mes=None
    balance_send = 0
    balance_rec = 0
    mes = "blank message"
    try:
        response,message =  chatchain.get_my_chain_send(send)
        send_rec = response
        response,message =  chatchain.get_my_chain_rec(rec)
        lod_rec = response
        mes1,val,mes2,ind = chatchain.valid_rec()
        print (f'val:: {val}')
        if val == False:
            p=False 
            mes = f"Recipient: {rec} Blockchain is not valid. {mes2} at Index {ind}"
        print(mes)
        p=True
        #if z==False:
        #    mes = b_mes
        #    p=False
    except Exception as e:
        mes = f"An Error Occured: {e}" 
        p=False
    print (mes)
    
    if p==False:
        return (mes, p,None,None,None,None,None,None,None,None,None,None,None)
    if p==True:
        chatchain.mychain_send.new_transaction(f"{send}",f"{rec}",f"{amount}")
        message_send = "Transaction Added to Pool"
        data_send = pd.DataFrame(chatchain.mychain_send.pending_transactions)
        chatchain.mychain_rec.new_transaction(f"{send}",f"{rec}",f"{amount}")
        message_rec = "Transaction Added to Pool"
        data_rec = pd.DataFrame(chatchain.mychain_rec.pending_transactions)
        response_send, show_chain_send, message_send = chatchain.mychain_mine_block_send(chain_r=None,chain_n=send)
        
        #mychain_mine_block_trans(balance_send, chain_r=None,chain_n=send)
        
        response_rec, show_chain_rec, message_rec =  chatchain.mychain_mine_block_rec(chain_r=None,chain_n=rec)
        mes = (f'Send: {message_send} :: Recieve: {message_rec}')
        _,rec_send=update_send_list()
        _,rec_drop=update_rec_list()
        #trans_bx = merge_trans()
        #trans_data, mes = bc_utils.bc_transactions(trans_bx)
        return (mes)
        




with gr.Blocks() as app:
    with gr.Row(visible=True) as invalid:
        pass_box = gr.Textbox()
        pass_btn = gr.Button()
        
    with gr.Group(visible=False) as valida: 
        gr.Column()
        with gr.Column():
            with gr.Row():
                with gr.Tab("Messages"):
                    with gr.Accordion("Key"):
                        input_key = gr.Image(label="Key",type="filepath")
                            
                    with gr.Row():
                        with gr.Column():
                            sender=gr.Textbox(label = "Sender", interactive = False)
                            rec=gr.Dropdown(label="Recipient", choices=[f for f in rec_list], allow_custom_value=True, interactive=True)
                            send_mes=gr.Textbox(label="Message", lines=6)
                            send_mes_btn=gr.Button()
                        with gr.Column():
                            block_text = gr.Textbox(label = "System", interactive = False)
                            response_json=gr.JSON()
                            rec_mes = gr.Textbox(lines=6)
            
            
                        
                with gr.Tab("BC"):
                    with gr.Row():
                        with gr.Tab("Gen Wal"):
                            gen_wal_btn=gr.Button()
                            seed = gr.Textbox(label='Seed Phrase')
                            img1=gr.Image(label='Private Key',type='filepath')
                            out1 = gr.Textbox(label='Private Key',max_lines=4)
                            img2=gr.Pil(label='Public Key')
                            out2 = gr.Textbox(label='Public Key',max_lines=4)
                            img3=gr.Pil(label='Address')
                            out3 = gr.Textbox(label='Address')
                        with gr.Tab("Encrypt"):
                            rsa_to_enc = gr.Textbox(label="txt to encrypt")
                            pub_key_in = gr.Image(label="Public Key", type="filepath")
                            priv_key_in1 = gr.Image(label="Private Key(sig)", type="filepath")
                            rsa_enc_btn = gr.Button("RSA Encrypt")
                            rsa_enc_mes = gr.Textbox(label="encoded", max_lines=4)
                            qr_enc_mes = gr.Image(type="filepath")
                        with gr.Tab("Decrypt"):
                            mes_in = gr.Image(label="Message", type="filepath")
                            priv_key_in = gr.Image(label="Private Key", type="filepath")
                            rsa_dec_btn = gr.Button("RSA Decrypt")
                            rsa_dec_mes = gr.Textbox(label="decoded")
            in_chain=gr.Textbox(value=main_chain,visible=False)
        gr.Column()
    def test_fn(im):
        return (im)
    def create_new_chain(address,im):
        address = str(address.strip("b").strip("'"))
        mychain_rec = chatchain.MyChainRec(chain_load=f'{main_chain}{address}/',create=address)
        chatchain.store_image(img=im,chain_load=f'{main_chain}',address=address)
        response = {'chain': mychain_rec.chain,
                'length': len(mychain_rec.chain)}
        message = f"Blockchain loaded from: {main_chain}{address}.json"
        #send_list,send_drop = update_send_list()
        
        rec_list,rec_drop = chatchain.update_rec_list()
        #rec_drop = gr.Dropdown.update(label="Recipient", choices=[f for f in rec_list])
        return response,message,rec_drop      
    def rec_list_up(inp):
        _,out = chatchain.update_rec_list(inp)
        return (out)
    send_mes_btn.click(send_message,[sender,rec,send_mes],[block_text])

        
    input_key.change(crypt.address,input_key,sender).then(rec_list_up,in_chain,rec)
    pass_btn.click(checkp,pass_box,[invalid,valida])

    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])
    rsa_enc_btn.click(crypt.encrypt_text,[rsa_to_enc,pub_key_in,priv_key_in1,out3],[rsa_enc_mes,qr_enc_mes])
    rsa_dec_btn.click(crypt.decrypt_text,[mes_in,priv_key_in],rsa_dec_mes)                

app.launch()