chat-ap / app.py
Omnibus's picture
Update app.py
089bad2
raw
history blame
4.64 kB
import gradio as gr
import chatchain
import crypt
import os
rec_list = []
pa=os.environ['PASS']
main_chain='https://huggingface.co/datasets/Omnibus/chat-at/raw/main/chat/'
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)
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)
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.Pil(label='Private Key')
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")
gr.Column()
def test_fn(im):
return (im)
def update_rec_list():
f_ist = (api.list_repo_files(repo_id=f'{repo}/{name}', repo_type="dataset"))
rec_list =[]
for i,ea in enumerate(f_ist):
if "balance/" in ea:
try:
if not "__Source__" in ea:
rec_list.append(ea.split("/",1)[1].split(".",1)[0])
except Exception:
pass
return rec_list, gr.Dropdown.update(label="Recipient", choices=[f for f in rec_list])
rec_list, rec_drop = update_rec_list()
def create_new_chain(address):
address = str(address.strip("b").strip("'"))
mychain_rec = chatchain.MyChainRec(chain_load=main_chain,create=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 = update_rec_list()
return response,message,rec_drop
input_key.change(crypt.address,input_key,sender)
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,out1,[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()