aadya1762 commited on
Commit
2a738ad
·
1 Parent(s): c104b63

split to tabs

Browse files
Files changed (1) hide show
  1. gemmademo/_chat.py +121 -115
gemmademo/_chat.py CHANGED
@@ -101,126 +101,132 @@ class GradioChat:
101
  return gr.Dataset(samples=[[example] for example in examples])
102
 
103
  with gr.Blocks() as demo:
104
- with gr.Row():
105
- with gr.Column(scale=3): # Sidebar column
106
- with gr.Accordion(
107
- "Basic Settings ⚙️", open=False
108
- ): # Make the sidebar foldable
109
- gr.Markdown(
110
- "## Google Gemma Models: lightweight, state-of-the-art open models from Google"
111
- )
112
- task_dropdown = gr.Dropdown(
113
- choices=self.task_options,
114
- value=self.current_task_name,
115
- label="Select Task",
116
- )
117
- model_dropdown = gr.Dropdown(
118
- choices=self.model_options,
119
- value=self.current_model_name,
120
- label="Select Gemma Model",
121
- )
122
- chat_interface = gr.ChatInterface(
123
- chat_fn,
124
- additional_inputs=[model_dropdown, task_dropdown],
125
- textbox=gr.Textbox(
126
- placeholder="Ask me something...", container=False
127
- ),
128
- )
129
-
130
- with gr.Column(scale=1):
131
- gr.Markdown(
132
- """
133
- ## Tips
134
-
135
- - First response after model change will be slower (model loading lazily).
136
- - Switching models clears chat history.
137
- - Larger models need more memory but give better results.
138
- """
139
- )
140
- examples_list = gr.Examples(
141
- examples=[
142
- [example]
143
- for example in _get_examples(self.current_task_name)
144
- ],
145
- inputs=chat_interface.textbox,
146
- )
147
- task_dropdown.change(
148
- _update_examples, task_dropdown, examples_list.dataset
149
- )
150
- with gr.Accordion("Model Configuration ⚙️", open=False):
151
- temperature_slider = gr.Slider(
152
- minimum=0.1,
153
- maximum=2,
154
- value=self.model.temperature,
155
- label="Temperature",
156
- )
157
- gr.Markdown(
158
- "**Temperature:** Lower values make the output more deterministic."
159
- )
160
- temperature_slider.change(
161
- fn=lambda temp: setattr(self.model, "temperature", temp),
162
- inputs=temperature_slider,
163
- )
164
-
165
- top_p_slider = gr.Slider(
166
- minimum=0.1,
167
- maximum=1.0,
168
- value=self.model.top_p,
169
- label="Top P",
170
- )
171
- gr.Markdown(
172
- "**Top P:** Lower values make the output more focused."
173
- )
174
- top_p_slider.change(
175
- fn=lambda top_p: setattr(self.model, "top_p", top_p),
176
- inputs=top_p_slider,
177
- )
178
-
179
- top_k_slider = gr.Slider(
180
- minimum=1,
181
- maximum=100,
182
- value=self.model.top_k,
183
- label="Top K",
184
- )
185
- gr.Markdown(
186
- "**Top K:** Lower values make the output more focused."
187
- )
188
- top_k_slider.change(
189
- fn=lambda top_k: setattr(self.model, "top_k", top_k),
190
- inputs=top_k_slider,
191
- )
192
-
193
- repetition_penalty_slider = gr.Slider(
194
- minimum=1.0,
195
- maximum=2.0,
196
- value=self.model.repeat_penalty,
197
- label="Repetition Penalty",
198
- )
199
- gr.Markdown(
200
- "**Repetition Penalty:** Penalizes repeated tokens to reduce repetition in the output."
201
- )
202
- repetition_penalty_slider.change(
203
- fn=lambda penalty: setattr(
204
- self.model, "repeat_penalty", penalty
205
  ),
206
- inputs=repetition_penalty_slider,
207
  )
208
 
209
- max_tokens_slider = gr.Slider(
210
- minimum=512,
211
- maximum=2048,
212
- value=self.model.max_tokens,
213
- label="Max Tokens",
214
- )
215
  gr.Markdown(
216
- "**Max Tokens:** Sets the maximum number of tokens the model can generate in one response."
217
- )
218
- max_tokens_slider.change(
219
- fn=lambda max_tokens: setattr(
220
- self.model, "max_tokens", max_tokens
221
- ),
222
- inputs=max_tokens_slider,
223
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
 
225
  demo.launch()
226
 
 
101
  return gr.Dataset(samples=[[example] for example in examples])
102
 
103
  with gr.Blocks() as demo:
104
+ with gr.Tab("Model Playground"):
105
+ with gr.Row():
106
+ with gr.Column(scale=3): # Sidebar column
107
+ with gr.Accordion(
108
+ "Basic Settings ⚙️", open=False
109
+ ): # Make the sidebar foldable
110
+ gr.Markdown(
111
+ "## Google Gemma Models: lightweight, state-of-the-art open models from Google"
112
+ )
113
+ task_dropdown = gr.Dropdown(
114
+ choices=self.task_options,
115
+ value=self.current_task_name,
116
+ label="Select Task",
117
+ )
118
+ model_dropdown = gr.Dropdown(
119
+ choices=self.model_options,
120
+ value=self.current_model_name,
121
+ label="Select Gemma Model",
122
+ )
123
+ chat_interface = gr.ChatInterface(
124
+ chat_fn,
125
+ additional_inputs=[model_dropdown, task_dropdown],
126
+ textbox=gr.Textbox(
127
+ placeholder="Ask me something...", container=False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  ),
 
129
  )
130
 
131
+ with gr.Column(scale=1):
 
 
 
 
 
132
  gr.Markdown(
133
+ """
134
+ ## Tips
135
+
136
+ - First response after model change will be slower (model loading lazily).
137
+ - Switching models clears chat history.
138
+ - Larger models need more memory but give better results.
139
+ """
140
  )
141
+ examples_list = gr.Examples(
142
+ examples=[
143
+ [example]
144
+ for example in _get_examples(self.current_task_name)
145
+ ],
146
+ inputs=chat_interface.textbox,
147
+ )
148
+ task_dropdown.change(
149
+ _update_examples, task_dropdown, examples_list.dataset
150
+ )
151
+ with gr.Accordion("Model Configuration ⚙️", open=False):
152
+ temperature_slider = gr.Slider(
153
+ minimum=0.1,
154
+ maximum=2,
155
+ value=self.model.temperature,
156
+ label="Temperature",
157
+ )
158
+ gr.Markdown(
159
+ "**Temperature:** Lower values make the output more deterministic."
160
+ )
161
+ temperature_slider.change(
162
+ fn=lambda temp: setattr(
163
+ self.model, "temperature", temp
164
+ ),
165
+ inputs=temperature_slider,
166
+ )
167
+
168
+ top_p_slider = gr.Slider(
169
+ minimum=0.1,
170
+ maximum=1.0,
171
+ value=self.model.top_p,
172
+ label="Top P",
173
+ )
174
+ gr.Markdown(
175
+ "**Top P:** Lower values make the output more focused."
176
+ )
177
+ top_p_slider.change(
178
+ fn=lambda top_p: setattr(self.model, "top_p", top_p),
179
+ inputs=top_p_slider,
180
+ )
181
+
182
+ top_k_slider = gr.Slider(
183
+ minimum=1,
184
+ maximum=100,
185
+ value=self.model.top_k,
186
+ label="Top K",
187
+ )
188
+ gr.Markdown(
189
+ "**Top K:** Lower values make the output more focused."
190
+ )
191
+ top_k_slider.change(
192
+ fn=lambda top_k: setattr(self.model, "top_k", top_k),
193
+ inputs=top_k_slider,
194
+ )
195
+
196
+ repetition_penalty_slider = gr.Slider(
197
+ minimum=1.0,
198
+ maximum=2.0,
199
+ value=self.model.repeat_penalty,
200
+ label="Repetition Penalty",
201
+ )
202
+ gr.Markdown(
203
+ "**Repetition Penalty:** Penalizes repeated tokens to reduce repetition in the output."
204
+ )
205
+ repetition_penalty_slider.change(
206
+ fn=lambda penalty: setattr(
207
+ self.model, "repeat_penalty", penalty
208
+ ),
209
+ inputs=repetition_penalty_slider,
210
+ )
211
+
212
+ max_tokens_slider = gr.Slider(
213
+ minimum=512,
214
+ maximum=2048,
215
+ value=self.model.max_tokens,
216
+ label="Max Tokens",
217
+ )
218
+ gr.Markdown(
219
+ "**Max Tokens:** Sets the maximum number of tokens the model can generate in one response."
220
+ )
221
+ max_tokens_slider.change(
222
+ fn=lambda max_tokens: setattr(
223
+ self.model, "max_tokens", max_tokens
224
+ ),
225
+ inputs=max_tokens_slider,
226
+ )
227
+
228
+ with gr.Tab("Model Comparision"):
229
+ pass
230
 
231
  demo.launch()
232