Spaces:
Runtime error
Runtime error
| 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() |