File size: 3,293 Bytes
37e7cb8
6acc4d5
37e7cb8
 
56bfdb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import Iterator

import gradio as gr
import torch

MAX_MAX_NEW_TOKENS = 4096
DEFAULT_MAX_NEW_TOKENS = 1024
MAX_INPUT_TOKEN_LENGTH = 4000


with gr.Blocks(css='style.css') as demo: # 使用gr.Blocks库创建的Web界面的开始。css='style.css'指定了界面的样式表。
    gr.Markdown(DESCRIPTION) # 使用Markdown格式显示描述文本:DESCRIPTION
    gr.DuplicateButton(value='Duplicate Space for private use', # 复制按钮,允许复制作为私人使用
                       elem_id='duplicate-button')

    with gr.Group():  # 这是一个组,用于将一组元素组织在一起。
        chatbot = gr.Chatbot(label='Chatbot')
        with gr.Row(): # 这是一个行元素,将其中的元素排成一排
            # 这是一个文本框,用户可以在其中输入消息。
            textbox = gr.Textbox( 
                container=False,
                show_label=False,
                placeholder='Type a message...',
                scale=10,
            )
            # 这是一个提交按钮,用户可以点击它来发送消息。
            submit_button = gr.Button('Submit',
                                      variant='primary',
                                      scale=1,
                                      min_width=0)
            

    with gr.Row(): # 另一个行元素
        retry_button = gr.Button('🔄  Retry', variant='secondary')
        undo_button = gr.Button('↩️ Undo', variant='secondary')
        clear_button = gr.Button('🗑️  Clear', variant='secondary')

    saved_input = gr.State() # 这是一个状态变量,用于保存用户输入的消息

    with gr.Accordion(label='Advanced options', open=False): # 是一个可折叠的高级选项部分,用户可以展开或收起,可调节训练中参数值。
        system_prompt = gr.Textbox(label='System prompt',
                                   value=DEFAULT_SYSTEM_PROMPT,
                                   lines=6)
        max_new_tokens = gr.Slider( # 滑块
            label='Max new tokens',
            minimum=1,
            maximum=MAX_MAX_NEW_TOKENS,
            step=1,
            value=DEFAULT_MAX_NEW_TOKENS,
        )
        temperature = gr.Slider( # 预热值
            label='Temperature',
            minimum=0.1,
            maximum=4.0,
            step=0.1,
            value=0.1,
        )
        top_p = gr.Slider(
            label='Top-p (nucleus sampling)',
            minimum=0.05,
            maximum=1.0,
            step=0.05,
            value=0.9,
        )
        top_k = gr.Slider(
            label='Top-k',
            minimum=1,
            maximum=1000,
            step=1,
            value=10,
        )
        repetition_penalty = gr.Slider(
            label = 'Repetition_penalty',
            minimum = 0.1,
            maximum = 3.0,
            step = 0.1,
            value = 1.0,
        )

        gr.Examples(
        examples=[
            'What is the Fibonacci sequence?',
            'Can you explain briefly what Python is good for?',
            'How can I display a grid of images in SwiftUI?',
        ],
        inputs=textbox,
        outputs=[textbox, chatbot],
        fn=process_example,
        cache_examples=True,
    )

demo.queue(max_size=20).launch()