Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -100,30 +100,49 @@ def submit(message, history, model_name, max_tokens, temperature, top_p):
|
|
100 |
for updated_history in respond(message, history, model_name, max_tokens, temperature, top_p):
|
101 |
yield updated_history, ""
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
# Create the Gradio interface with Blocks
|
104 |
-
with gr.Blocks() as demo:
|
105 |
# Title and description
|
106 |
gr.Markdown("# LeCarnet")
|
107 |
gr.Markdown("Select a model on the right and type a message to chat.")
|
108 |
|
109 |
-
# Two-column layout
|
110 |
with gr.Row():
|
111 |
-
# Left column: Chat interface
|
112 |
-
with gr.Column():
|
113 |
chatbot = gr.Chatbot(
|
114 |
avatar_images=(None, "media/le-carnet.png"), # User avatar: None, Bot avatar: Logo
|
115 |
-
label="Chat"
|
|
|
116 |
)
|
117 |
user_input = gr.Textbox(placeholder="Type your message here...", label="Message")
|
118 |
submit_btn = gr.Button("Send")
|
119 |
|
120 |
-
# Right column: Model selection and parameters
|
121 |
-
with gr.Column():
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
)
|
|
|
|
|
|
|
|
|
|
|
127 |
max_tokens = gr.Slider(1, 512, value=512, step=1, label="Max New Tokens")
|
128 |
temperature = gr.Slider(0.1, 2.0, value=0.7, step=0.1, label="Temperature")
|
129 |
top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
|
@@ -141,9 +160,26 @@ with gr.Blocks() as demo:
|
|
141 |
# Event handling for submit button
|
142 |
submit_btn.click(
|
143 |
fn=submit,
|
144 |
-
inputs=[user_input, chatbot,
|
145 |
outputs=[chatbot, user_input],
|
146 |
)
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
if __name__ == "__main__":
|
149 |
demo.queue(default_concurrency_limit=10, max_size=10).launch(ssr_mode=False, max_threads=10)
|
|
|
100 |
for updated_history in respond(message, history, model_name, max_tokens, temperature, top_p):
|
101 |
yield updated_history, ""
|
102 |
|
103 |
+
def select_model(model_name, current_model):
|
104 |
+
"""
|
105 |
+
Update the selected model name when a model button is clicked.
|
106 |
+
|
107 |
+
Args:
|
108 |
+
model_name (str): The model name to select.
|
109 |
+
current_model (str): The currently selected model.
|
110 |
+
|
111 |
+
Returns:
|
112 |
+
str: The newly selected model name.
|
113 |
+
"""
|
114 |
+
return model_name
|
115 |
+
|
116 |
# Create the Gradio interface with Blocks
|
117 |
+
with gr.Blocks(css=".gr-button {margin: 5px; width: 100%;} .gr-column {padding: 10px;}") as demo:
|
118 |
# Title and description
|
119 |
gr.Markdown("# LeCarnet")
|
120 |
gr.Markdown("Select a model on the right and type a message to chat.")
|
121 |
|
122 |
+
# Two-column layout with specific widths
|
123 |
with gr.Row():
|
124 |
+
# Left column: Chat interface (80% width)
|
125 |
+
with gr.Column(scale=4):
|
126 |
chatbot = gr.Chatbot(
|
127 |
avatar_images=(None, "media/le-carnet.png"), # User avatar: None, Bot avatar: Logo
|
128 |
+
label="Chat",
|
129 |
+
height=600, # Increase chat height for larger display
|
130 |
)
|
131 |
user_input = gr.Textbox(placeholder="Type your message here...", label="Message")
|
132 |
submit_btn = gr.Button("Send")
|
133 |
|
134 |
+
# Right column: Model selection and parameters (20% width)
|
135 |
+
with gr.Column(scale=1, min_width=200):
|
136 |
+
# State to track selected model
|
137 |
+
model_state = gr.State(value="LeCarnet-8M")
|
138 |
+
|
139 |
+
# Model selection buttons
|
140 |
+
gr.Markdown("**Select Model**")
|
141 |
+
btn_3m = gr.Button("LeCarnet-3M")
|
142 |
+
btn_8m = gr.Button("LeCarnet-8M")
|
143 |
+
btn_21m = gr.Button("LeCarnet-21M")
|
144 |
+
|
145 |
+
# Sliders for parameters
|
146 |
max_tokens = gr.Slider(1, 512, value=512, step=1, label="Max New Tokens")
|
147 |
temperature = gr.Slider(0.1, 2.0, value=0.7, step=0.1, label="Temperature")
|
148 |
top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
|
|
|
160 |
# Event handling for submit button
|
161 |
submit_btn.click(
|
162 |
fn=submit,
|
163 |
+
inputs=[user_input, chatbot, model_state, max_tokens, temperature, top_p],
|
164 |
outputs=[chatbot, user_input],
|
165 |
)
|
166 |
|
167 |
+
# Event handling for model selection buttons
|
168 |
+
btn_3m.click(
|
169 |
+
fn=select_model,
|
170 |
+
inputs=[gr.State("LeCarnet-3M"), model_state],
|
171 |
+
outputs=model_state,
|
172 |
+
)
|
173 |
+
btn_8m.click(
|
174 |
+
fn=select_model,
|
175 |
+
inputs=[gr.State("LeCarnet-8M"), model_state],
|
176 |
+
outputs=model_state,
|
177 |
+
)
|
178 |
+
btn_21m.click(
|
179 |
+
fn=select_model,
|
180 |
+
inputs=[gr.State("LeCarnet-21M"), model_state],
|
181 |
+
outputs=model_state,
|
182 |
+
)
|
183 |
+
|
184 |
if __name__ == "__main__":
|
185 |
demo.queue(default_concurrency_limit=10, max_size=10).launch(ssr_mode=False, max_threads=10)
|