Spaces:
Runtime error
Runtime error
Commit
·
37e7cb8
1
Parent(s):
6acc4d5
pip install torch
Browse files
app.py
CHANGED
|
@@ -1,187 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
with gr.Blocks(css='style.css') as demo:
|
| 4 |
-
gr.Markdown(DESCRIPTION)
|
| 5 |
-
gr.DuplicateButton(value='Duplicate Space for private use',
|
| 6 |
-
elem_id='duplicate-button')
|
| 7 |
-
|
| 8 |
-
with gr.Group():
|
| 9 |
-
chatbot = gr.Chatbot(label='Chatbot')
|
| 10 |
-
with gr.Row():
|
| 11 |
-
textbox = gr.Textbox(
|
| 12 |
-
container=False,
|
| 13 |
-
show_label=False,
|
| 14 |
-
placeholder='Type a message...',
|
| 15 |
-
scale=10,
|
| 16 |
-
)
|
| 17 |
-
submit_button = gr.Button('Submit',
|
| 18 |
-
variant='primary',
|
| 19 |
-
scale=1,
|
| 20 |
-
min_width=0)
|
| 21 |
-
with gr.Row():
|
| 22 |
-
retry_button = gr.Button('🔄 Retry', variant='secondary')
|
| 23 |
-
undo_button = gr.Button('↩️ Undo', variant='secondary')
|
| 24 |
-
clear_button = gr.Button('🗑️ Clear', variant='secondary')
|
| 25 |
-
|
| 26 |
-
saved_input = gr.State()
|
| 27 |
-
|
| 28 |
-
with gr.Accordion(label='Advanced options', open=False):
|
| 29 |
-
system_prompt = gr.Textbox(label='System prompt',
|
| 30 |
-
value=DEFAULT_SYSTEM_PROMPT,
|
| 31 |
-
lines=6)
|
| 32 |
-
max_new_tokens = gr.Slider(
|
| 33 |
-
label='Max new tokens',
|
| 34 |
-
minimum=1,
|
| 35 |
-
maximum=MAX_MAX_NEW_TOKENS,
|
| 36 |
-
step=1,
|
| 37 |
-
value=DEFAULT_MAX_NEW_TOKENS,
|
| 38 |
-
)
|
| 39 |
-
temperature = gr.Slider(
|
| 40 |
-
label='Temperature',
|
| 41 |
-
minimum=0.1,
|
| 42 |
-
maximum=4.0,
|
| 43 |
-
step=0.1,
|
| 44 |
-
value=0.1,
|
| 45 |
-
)
|
| 46 |
-
top_p = gr.Slider(
|
| 47 |
-
label='Top-p (nucleus sampling)',
|
| 48 |
-
minimum=0.05,
|
| 49 |
-
maximum=1.0,
|
| 50 |
-
step=0.05,
|
| 51 |
-
value=0.9,
|
| 52 |
-
)
|
| 53 |
-
top_k = gr.Slider(
|
| 54 |
-
label='Top-k',
|
| 55 |
-
minimum=1,
|
| 56 |
-
maximum=1000,
|
| 57 |
-
step=1,
|
| 58 |
-
value=10,
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
gr.Examples(
|
| 62 |
-
examples=[
|
| 63 |
-
'What is the Fibonacci sequence?',
|
| 64 |
-
'Can you explain briefly what Python is good for?',
|
| 65 |
-
'How can I display a grid of images in SwiftUI?',
|
| 66 |
-
],
|
| 67 |
-
inputs=textbox,
|
| 68 |
-
outputs=[textbox, chatbot],
|
| 69 |
-
fn=process_example,
|
| 70 |
-
cache_examples=True,
|
| 71 |
-
)
|
| 72 |
-
|
| 73 |
-
gr.Markdown(LICENSE)
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
inputs=textbox,
|
| 78 |
-
outputs=[textbox, saved_input],
|
| 79 |
-
api_name=False,
|
| 80 |
-
queue=False,
|
| 81 |
-
).then(
|
| 82 |
-
fn=display_input,
|
| 83 |
-
inputs=[saved_input, chatbot],
|
| 84 |
-
outputs=chatbot,
|
| 85 |
-
api_name=False,
|
| 86 |
-
queue=False,
|
| 87 |
-
).then(
|
| 88 |
-
fn=check_input_token_length,
|
| 89 |
-
inputs=[saved_input, chatbot, system_prompt],
|
| 90 |
-
api_name=False,
|
| 91 |
-
queue=False,
|
| 92 |
-
).success(
|
| 93 |
-
fn=generate,
|
| 94 |
-
inputs=[
|
| 95 |
-
saved_input,
|
| 96 |
-
chatbot,
|
| 97 |
-
system_prompt,
|
| 98 |
-
max_new_tokens,
|
| 99 |
-
temperature,
|
| 100 |
-
top_p,
|
| 101 |
-
top_k,
|
| 102 |
-
],
|
| 103 |
-
outputs=chatbot,
|
| 104 |
-
api_name=False,
|
| 105 |
-
)
|
| 106 |
-
|
| 107 |
-
button_event_preprocess = submit_button.click(
|
| 108 |
-
fn=clear_and_save_textbox,
|
| 109 |
-
inputs=textbox,
|
| 110 |
-
outputs=[textbox, saved_input],
|
| 111 |
-
api_name=False,
|
| 112 |
-
queue=False,
|
| 113 |
-
).then(
|
| 114 |
-
fn=display_input,
|
| 115 |
-
inputs=[saved_input, chatbot],
|
| 116 |
-
outputs=chatbot,
|
| 117 |
-
api_name=False,
|
| 118 |
-
queue=False,
|
| 119 |
-
).then(
|
| 120 |
-
fn=check_input_token_length,
|
| 121 |
-
inputs=[saved_input, chatbot, system_prompt],
|
| 122 |
-
api_name=False,
|
| 123 |
-
queue=False,
|
| 124 |
-
).success(
|
| 125 |
-
fn=generate,
|
| 126 |
-
inputs=[
|
| 127 |
-
saved_input,
|
| 128 |
-
chatbot,
|
| 129 |
-
system_prompt,
|
| 130 |
-
max_new_tokens,
|
| 131 |
-
temperature,
|
| 132 |
-
top_p,
|
| 133 |
-
top_k,
|
| 134 |
-
],
|
| 135 |
-
outputs=chatbot,
|
| 136 |
-
api_name=False,
|
| 137 |
-
)
|
| 138 |
-
|
| 139 |
-
retry_button.click(
|
| 140 |
-
fn=delete_prev_fn,
|
| 141 |
-
inputs=chatbot,
|
| 142 |
-
outputs=[chatbot, saved_input],
|
| 143 |
-
api_name=False,
|
| 144 |
-
queue=False,
|
| 145 |
-
).then(
|
| 146 |
-
fn=display_input,
|
| 147 |
-
inputs=[saved_input, chatbot],
|
| 148 |
-
outputs=chatbot,
|
| 149 |
-
api_name=False,
|
| 150 |
-
queue=False,
|
| 151 |
-
).then(
|
| 152 |
-
fn=generate,
|
| 153 |
-
inputs=[
|
| 154 |
-
saved_input,
|
| 155 |
-
chatbot,
|
| 156 |
-
system_prompt,
|
| 157 |
-
max_new_tokens,
|
| 158 |
-
temperature,
|
| 159 |
-
top_p,
|
| 160 |
-
top_k,
|
| 161 |
-
],
|
| 162 |
-
outputs=chatbot,
|
| 163 |
-
api_name=False,
|
| 164 |
-
)
|
| 165 |
-
|
| 166 |
-
undo_button.click(
|
| 167 |
-
fn=delete_prev_fn,
|
| 168 |
-
inputs=chatbot,
|
| 169 |
-
outputs=[chatbot, saved_input],
|
| 170 |
-
api_name=False,
|
| 171 |
-
queue=False,
|
| 172 |
-
).then(
|
| 173 |
-
fn=lambda x: x,
|
| 174 |
-
inputs=[saved_input],
|
| 175 |
-
outputs=textbox,
|
| 176 |
-
api_name=False,
|
| 177 |
-
queue=False,
|
| 178 |
-
)
|
| 179 |
-
|
| 180 |
-
clear_button.click(
|
| 181 |
-
fn=lambda: ([], ''),
|
| 182 |
-
outputs=[chatbot, saved_input],
|
| 183 |
-
queue=False,
|
| 184 |
-
api_name=False,
|
| 185 |
-
)
|
| 186 |
-
|
| 187 |
-
demo.queue(max_size=20).launch()
|
|
|
|
| 1 |
+
from typing import Iterator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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