Spaces:
Running
Running
import io | |
import gradio as gr | |
from PIL import Image | |
from login import catch_qr, get_uid_key | |
from nft import up_card | |
def qr(ava_image): | |
if ava_image is not None: | |
height, width = ava_image.shape[:2] | |
if height < 1024 and width < 1024: | |
qr_img, info = catch_qr(ava_image) | |
return {image_qr: qr_img, login_info: info} | |
return {image_qr: None, login_info: None} | |
def login_up_nft(ava_image, info): | |
if info is not None: | |
result, uid, key, code = get_uid_key(info) | |
if result: | |
image = Image.fromarray(ava_image) | |
bytes_object = io.BytesIO() | |
image.save(bytes_object, format='JPEG') | |
img_data = bytes_object.getvalue() | |
result, code = up_card(uid, key, img_data) | |
return code | |
else: | |
return code | |
return "请先上传头像和扫码登录" | |
with gr.Blocks() as demo: | |
login_info = gr.State([]) | |
with gr.Tab("bili_NFT自定义头像"): | |
gr.Markdown("30秒自定义钻石头像(NFT),一站式操作仅三步,无需下载安装,代码开源") | |
gr.Markdown("第一步:") | |
gr.Markdown("""领取三体数字藏品R级别,作为自定义NFT头像底图. | |
[三体数字藏品领取地址](https://www.bilibili.com/h5/mall/v2/card/collection?act_id=14&hybrid_set_header=2)""") | |
gr.Markdown("""https://www.bilibili.com/h5/mall/v2/card/collection?act_id=14&hybrid_set_header=2""") | |
gr.Markdown("第二步:") | |
with gr.Row(): | |
with gr.Column(): | |
gr.Markdown("确保第一步领取三体数字藏品后,上传新头像,头像尽量为正方形并小于1024*1024像素,然后等待生成二维码并扫码登录进行授权(左上传头像,右扫码登录))") | |
image_ava = gr.Image() | |
image_qr = gr.Image() | |
gr.Markdown("第三步:") | |
with gr.Row(): | |
gr.Markdown("""第二步完成后,3-15s内点击按钮<验证登录并提交头像>等待任务完成显示结果(成功可能需要时间审核)""") | |
text_button = gr.Button("验证登录并提交头像") | |
code_output = gr.Textbox(placeholder="提交结果") | |
with gr.Accordion("代码来源及郑重提醒"): | |
gr.Markdown("https://github.com/wdvipa/custom_bilibili_nft") | |
gr.Markdown("https://github.com/XiaoMiku01/custom_bilibili_nft") | |
gr.Markdown("https://github.com/cibimo/bilibiliLogin") | |
gr.Markdown("本软件纯属娱乐,不得用于其他用途,秋后算账别怨我!") | |
image_ava.change(qr, inputs=[image_ava], outputs=[image_qr, login_info]) | |
text_button.click(login_up_nft, inputs=[image_ava, login_info], outputs=[code_output]) | |
demo.launch() | |