File size: 1,430 Bytes
a8c39f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import sys
import json

now_dir = os.getcwd()
sys.path.append(now_dir)

import gradio as gr
from assets.i18n.i18n import I18nAuto

i18n = I18nAuto()


def set_model_author(model_author: str):
    with open(os.path.join(now_dir, "assets", "config.json"), "r") as f:
        config = json.load(f)

    config["model_author"] = model_author

    with open(os.path.join(now_dir, "assets", "config.json"), "w") as f:
        json.dump(config, f, indent=4)

    print(f"Model author set to {model_author}.")
    return f"Model author set to {model_author}."


def get_model_author():
    with open(os.path.join(now_dir, "assets", "config.json"), "r") as f:
        config = json.load(f)

    return config["model_author"] if "model_author" in config else None


def model_author_tab():
    model_author_name = gr.Textbox(
        label=i18n("Model Author Name"),
        info=i18n("The name that will appear in the model information."),
        value=get_model_author(),
        placeholder=i18n("Enter your nickname"),
        interactive=True,
    )
    model_author_output_info = gr.Textbox(
        label=i18n("Output Information"),
        info=i18n("The output information will be displayed here."),
        value="",
        max_lines=1,
    )
    button = gr.Button(i18n("Set name"))

    button.click(
        fn=set_model_author,
        inputs=[model_author_name],
        outputs=[model_author_output_info],
    )