Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,140 @@
|
|
|
|
|
|
1 |
from styles import MODEL_SELECTION_CSS
|
2 |
from js import GET_LOCAL_STORAGE, UPDATE_LEFT_BTNS_STATE, UPDATE_PLACEHOLDERS
|
3 |
from templates import templates
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
from styles import MODEL_SELECTION_CSS
|
4 |
from js import GET_LOCAL_STORAGE, UPDATE_LEFT_BTNS_STATE, UPDATE_PLACEHOLDERS
|
5 |
from templates import templates
|
6 |
+
|
7 |
+
with gr.Blocks(css=MODEL_SELECTION_CSS, theme='gradio/soft') as demo:
|
8 |
+
with gr.Column(visible=False) as chat_view:
|
9 |
+
idx = gr.State(0)
|
10 |
+
chat_state = gr.State()
|
11 |
+
local_data = gr.JSON({}, visible=False)
|
12 |
+
|
13 |
+
with gr.Row():
|
14 |
+
with gr.Column(scale=1, min_width=180):
|
15 |
+
gr.Markdown("GradioChat", elem_id="left-top")
|
16 |
+
|
17 |
+
with gr.Column(elem_id="left-pane"):
|
18 |
+
chat_back_btn = gr.Button("Back", elem_id="chat-back-btn")
|
19 |
+
|
20 |
+
with gr.Accordion("Histories", elem_id="chat-history-accordion", open=False):
|
21 |
+
channel_btns.append(gr.Button(channels[0], elem_classes=["custom-btn-highlight"]))
|
22 |
+
|
23 |
+
for channel in channels[1:]:
|
24 |
+
channel_btns.append(gr.Button(channel, elem_classes=["custom-btn"]))
|
25 |
+
|
26 |
+
with gr.Column(scale=8, elem_id="right-pane"):
|
27 |
+
with gr.Column(
|
28 |
+
elem_id="initial-popup", visible=False
|
29 |
+
) as example_block:
|
30 |
+
with gr.Row(scale=1):
|
31 |
+
with gr.Column(elem_id="initial-popup-left-pane"):
|
32 |
+
gr.Markdown("GradioChat", elem_id="initial-popup-title")
|
33 |
+
gr.Markdown("Making the community's best AI chat models available to everyone.")
|
34 |
+
with gr.Column(elem_id="initial-popup-right-pane"):
|
35 |
+
gr.Markdown("Chat UI is now open sourced on Hugging Face Hub")
|
36 |
+
gr.Markdown("check out the [↗ repository](https://huggingface.co/spaces/chansung/test-multi-conv)")
|
37 |
+
|
38 |
+
with gr.Column(scale=1):
|
39 |
+
gr.Markdown("Examples")
|
40 |
+
with gr.Row():
|
41 |
+
for example in examples:
|
42 |
+
ex_btns.append(gr.Button(example, elem_classes=["example-btn"]))
|
43 |
+
|
44 |
+
with gr.Column(elem_id="aux-btns-popup", visible=True):
|
45 |
+
with gr.Row():
|
46 |
+
stop = gr.Button("Stop", elem_classes=["aux-btn"])
|
47 |
+
regenerate = gr.Button("Regen", interactive=False, elem_classes=["aux-btn"])
|
48 |
+
clean = gr.Button("Clean", elem_classes=["aux-btn"])
|
49 |
+
|
50 |
+
with gr.Accordion("Context Inspector", elem_id="aux-viewer", open=False):
|
51 |
+
context_inspector = gr.Textbox(
|
52 |
+
"",
|
53 |
+
elem_id="aux-viewer-inspector",
|
54 |
+
label="",
|
55 |
+
lines=30,
|
56 |
+
max_lines=50,
|
57 |
+
)
|
58 |
+
|
59 |
+
chatbot = gr.Chatbot(elem_id='chatbot')
|
60 |
+
instruction_txtbox = gr.Textbox(placeholder="Ask anything", label="", elem_id="prompt-txt")
|
61 |
+
|
62 |
+
with gr.Accordion("Example Templates", open=False):
|
63 |
+
template_txt = gr.Textbox(visible=False)
|
64 |
+
template_md = gr.Markdown(label="Chosen Template", visible=False, elem_classes="template-txt")
|
65 |
+
|
66 |
+
with gr.Row():
|
67 |
+
placeholder_txt1 = gr.Textbox(label="placeholder #1", visible=False, interactive=True)
|
68 |
+
placeholder_txt2 = gr.Textbox(label="placeholder #2", visible=False, interactive=True)
|
69 |
+
placeholder_txt3 = gr.Textbox(label="placeholder #3", visible=False, interactive=True)
|
70 |
+
|
71 |
+
for template in templates:
|
72 |
+
with gr.Tab(template['title']):
|
73 |
+
gr.Examples(
|
74 |
+
template['template'],
|
75 |
+
inputs=[template_txt],
|
76 |
+
outputs=[template_md, placeholder_txt1, placeholder_txt2, placeholder_txt3, instruction_txtbox],
|
77 |
+
run_on_click=True,
|
78 |
+
fn=fill_up_placeholders,
|
79 |
+
)
|
80 |
+
|
81 |
+
with gr.Accordion("Control Panel", open=False) as control_panel:
|
82 |
+
with gr.Column():
|
83 |
+
with gr.Column():
|
84 |
+
gr.Markdown("#### Global context")
|
85 |
+
with gr.Accordion("global context will persist during conversation, and it is placed at the top of the prompt", open=False):
|
86 |
+
global_context = gr.Textbox(
|
87 |
+
"global context",
|
88 |
+
lines=5,
|
89 |
+
max_lines=10,
|
90 |
+
interactive=True,
|
91 |
+
elem_id="global-context"
|
92 |
+
)
|
93 |
+
|
94 |
+
gr.Markdown("#### Internet search")
|
95 |
+
with gr.Row():
|
96 |
+
internet_option = gr.Radio(choices=["on", "off"], value="off", label="mode")
|
97 |
+
serper_api_key = gr.Textbox(
|
98 |
+
value= "" if args.serper_api_key is None else args.serper_api_key,
|
99 |
+
placeholder="Get one by visiting serper.dev",
|
100 |
+
label="Serper api key"
|
101 |
+
)
|
102 |
+
|
103 |
+
gr.Markdown("#### GenConfig for **response** text generation")
|
104 |
+
with gr.Row():
|
105 |
+
res_temp = gr.Slider(0.0, 2.0, 0, step=0.1, label="temp", interactive=True)
|
106 |
+
res_topp = gr.Slider(0.0, 2.0, 0, step=0.1, label="top_p", interactive=True)
|
107 |
+
res_topk = gr.Slider(20, 1000, 0, step=1, label="top_k", interactive=True)
|
108 |
+
res_rpen = gr.Slider(0.0, 2.0, 0, step=0.1, label="rep_penalty", interactive=True)
|
109 |
+
res_mnts = gr.Slider(64, 8192, 0, step=1, label="new_tokens", interactive=True)
|
110 |
+
res_beams = gr.Slider(1, 4, 0, step=1, label="beams")
|
111 |
+
res_cache = gr.Radio([True, False], value=0, label="cache", interactive=True)
|
112 |
+
res_sample = gr.Radio([True, False], value=0, label="sample", interactive=True)
|
113 |
+
res_eosid = gr.Number(value=0, visible=False, precision=0)
|
114 |
+
res_padid = gr.Number(value=0, visible=False, precision=0)
|
115 |
+
|
116 |
+
with gr.Column(visible=False):
|
117 |
+
gr.Markdown("#### GenConfig for **summary** text generation")
|
118 |
+
with gr.Row():
|
119 |
+
sum_temp = gr.Slider(0.0, 2.0, 0, step=0.1, label="temp", interactive=True)
|
120 |
+
sum_topp = gr.Slider(0.0, 2.0, 0, step=0.1, label="top_p", interactive=True)
|
121 |
+
sum_topk = gr.Slider(20, 1000, 0, step=1, label="top_k", interactive=True)
|
122 |
+
sum_rpen = gr.Slider(0.0, 2.0, 0, step=0.1, label="rep_penalty", interactive=True)
|
123 |
+
sum_mnts = gr.Slider(64, 8192, 0, step=1, label="new_tokens", interactive=True)
|
124 |
+
sum_beams = gr.Slider(1, 8, 0, step=1, label="beams", interactive=True)
|
125 |
+
sum_cache = gr.Radio([True, False], value=0, label="cache", interactive=True)
|
126 |
+
sum_sample = gr.Radio([True, False], value=0, label="sample", interactive=True)
|
127 |
+
sum_eosid = gr.Number(value=0, visible=False, precision=0)
|
128 |
+
sum_padid = gr.Number(value=0, visible=False, precision=0)
|
129 |
+
|
130 |
+
with gr.Column():
|
131 |
+
gr.Markdown("#### Context managements")
|
132 |
+
with gr.Row():
|
133 |
+
ctx_num_lconv = gr.Slider(2, 10, 3, step=1, label="number of recent talks to keep", interactive=True)
|
134 |
+
ctx_sum_prompt = gr.Textbox(
|
135 |
+
"summarize our conversations. what have we discussed about so far?",
|
136 |
+
label="design a prompt to summarize the conversations",
|
137 |
+
visible=False
|
138 |
+
)
|
139 |
+
|
140 |
+
demo.launch()
|