File size: 3,697 Bytes
c9ecd6c
 
 
 
 
 
 
4df7720
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c9ecd6c
 
 
7a6fcc0
 
c9ecd6c
 
 
4df7720
c9ecd6c
 
 
 
dba73a2
c9ecd6c
4df7720
 
c9ecd6c
 
 
 
 
 
 
 
 
dba73a2
f97bbf2
bbdde2c
dba73a2
f97bbf2
7a6fcc0
c9ecd6c
 
 
 
 
 
 
7a6fcc0
 
dba73a2
 
c9ecd6c
 
7a6fcc0
4df7720
 
 
 
c9ecd6c
 
f97bbf2
c9ecd6c
 
 
 
 
 
4df7720
c9ecd6c
 
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
import io

import gradio as gr

from login import catch_qr, get_uid_key
from nft import up_card

sid_map = {
    "SHN48荣耀时刻": 1,
    "无": 2,
    "无2": 3,
    "胶囊计划": 4,
    "天官赐福": 5,
    "A - AKB48TSH四周年": 6,
    "B - AKB48TSH四周年": 7,
    "C - AKB48TSH四周年": 8,
    "D - AKB48TSH四周年": 9,
    "E - AKB48TSH四周年": 10,
    "F - AKB48TSH四周年": 11,
    "G - AKB48TSH四周年": 12,
    "H - AKB48TSH四周年": 13,
    "三体动画": 14
}
card_type_choices = list(sid_map.keys())


def qr(ava_image):
    if ava_image is not None:
        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, sid):
    if info is not None:
        result, uid, key, code = get_uid_key(info)
        if result:
            bytes_object = io.BytesIO()
            ava_image.save(bytes_object, format='PNG')
            img_data = bytes_object.getvalue()
            sid_id = sid_map[sid]
            result, code = up_card(uid, key, img_data, sid_id)
            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("""
            使用视频教程(欢迎三连):[视频地址](https://www.bilibili.com/video/BV1t8411P7HD/)
            https://www.bilibili.com/video/BV1t8411P7HD/
                    """)
        gr.Markdown("源码:https://huggingface.co/spaces/cynika/NFT_avatar")
        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(type="pil", label="上传头像")
            image_qr = gr.Image(type="pil", label="b站客户端扫码登录")
        gr.Markdown("第三步:")
        with gr.Row():
            gr.Markdown(
                """第二步完成后,选择拥有卡组(三体的不用选择),3-15s内点击按钮<验证并提交头像>等待完成显示结果(成功可能需要时间审核)""")
            with gr.Row():
                sid_drop = gr.Dropdown(label="卡组", choices=card_type_choices, value="三体动画")
                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, sid_drop], outputs=[code_output])

demo.launch()