janbanot commited on
Commit
b1632ff
1 Parent(s): 58567e1

feat: change interface

Browse files
Files changed (1) hide show
  1. app.py +236 -27
app.py CHANGED
@@ -88,37 +88,246 @@ def generate(
88
  yield cleaned_response
89
 
90
 
91
- def clear():
92
- return "", ""
 
 
 
 
 
 
 
93
 
 
 
 
 
 
94
 
95
- with gr.Blocks() as demo:
96
- gr.Markdown("# Bielik Tools - narz臋dzia dla modelu Bielik v2.3")
97
- gr.Markdown("Bielik czeka na Twoje pytanie - zadaj je 艣mia艂o i otrzymaj odpowied藕!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
- with gr.Row():
100
- prompt = gr.Textbox(
101
- label="Twoje pytanie", placeholder="Zadaj swoje pytanie tutaj...", lines=10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  )
103
- output = gr.Textbox(label="Answer", lines=10)
104
-
105
- with gr.Row():
106
- btn = gr.Button("Generuj odpowied藕")
107
- clear_btn = gr.Button("Wyczy艣膰")
108
-
109
- with gr.Accordion("鈿欙笍 Parametry", open=False):
110
- temperature = gr.Slider(0, 1, 0.3, step=0.1, label="Temperatura")
111
- max_tokens = gr.Slider(128, 4096, 1024, label="Maksymalna d艂ugo艣膰 odpowiedzi")
112
- top_k = gr.Slider(1, 80, 40, step=1, label="Top K")
113
- repetition_penalty = gr.Slider(
114
- 0, 2, 1.1, step=0.1, label="Penalizacja powt贸rze艅"
115
  )
116
- top_p = gr.Slider(0, 1, 0.95, step=0.05, label="Top P")
117
- btn.click(
118
- generate,
119
- inputs=[prompt, temperature, max_tokens, top_k, repetition_penalty, top_p],
120
- outputs=output,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  )
122
- clear_btn.click(clear, inputs=[], outputs=[prompt, output])
123
 
124
- demo.launch()
 
88
  yield cleaned_response
89
 
90
 
91
+ with gr.Blocks(
92
+ css="""
93
+ .gradio-container { max-width: 1600px; margin: 20px; padding: 10px; }
94
+ #style-dropdown { flex: 3; }
95
+ #generate-btn, #clear-btn { flex: 1; max-width: 100px; }
96
+ .same-height { height: 60px; }
97
+ """
98
+ ) as demo:
99
+ gr.Markdown("# Bielik Tools - narz臋dzia dla modelu Bielik v2.3")
100
 
101
+ with gr.Column(elem_id="main-content"):
102
+ with gr.Row():
103
+ simple_question_btn = gr.Button("Proste Pytanie", variant="primary")
104
+ formalizer_btn = gr.Button("Formalizator", variant="secondary")
105
+ judge_btn = gr.Button("S臋dzia", interactive=False)
106
 
107
+ # Function to switch tool visibility and update button styles based on the active tool
108
+ def switch_tool(tool):
109
+ print(f"Switched to {tool}")
110
+ return [
111
+ gr.Button(variant="primary" if tool == "Formalizer" else "secondary"),
112
+ gr.Button(variant="primary" if tool == "Judge" else "secondary"),
113
+ gr.Button(
114
+ variant="primary" if tool == "Simple Question" else "secondary"
115
+ ),
116
+ gr.update(visible=(tool == "Formalizer")),
117
+ gr.update(visible=(tool == "Judge")),
118
+ gr.update(visible=(tool == "Simple Question")),
119
+ ]
120
+
121
+ # Simple Question content column
122
+ with gr.Column(visible=True) as simple_question_column:
123
+ input_text_sq = gr.Textbox(
124
+ label="Twoje pytanie",
125
+ placeholder="Zadaj swoje pytanie tutaj...",
126
+ lines=5,
127
+ )
128
+ with gr.Row():
129
+ generate_btn_sq = gr.Button("Generuj odpowied藕", interactive=False)
130
+ clear_btn_sq = gr.Button("Wyczy艣膰", interactive=False)
131
+ output_text_sq = gr.Textbox(label="Odpowied藕", interactive=False)
132
+
133
+ with gr.Accordion("鈿欙笍 Parametry", open=False):
134
+ temperature_sq = gr.Slider(0, 1, 0.3, step=0.1, label="Temperatura")
135
+ max_tokens_sq = gr.Slider(
136
+ 128, 4096, 1024, label="Maksymalna d艂ugo艣膰 odpowiedzi"
137
+ )
138
+ top_k_sq = gr.Slider(1, 80, 40, step=1, label="Top K")
139
+ repetition_penalty_sq = gr.Slider(
140
+ 0, 2, 1.1, step=0.1, label="Penalizacja powt贸rze艅"
141
+ )
142
+ top_p_sq = gr.Slider(0, 1, 0.95, step=0.05, label="Top P")
143
+
144
+ # Update button states based on input and output text changes for interactivity
145
+ def update_button_states_sq(input_text, output_text):
146
+ return [
147
+ gr.update(interactive=bool(input_text)),
148
+ gr.update(interactive=bool(input_text or output_text)),
149
+ ]
150
+
151
+ input_text_sq.change(
152
+ update_button_states_sq,
153
+ inputs=[input_text_sq, output_text_sq],
154
+ outputs=[generate_btn_sq, clear_btn_sq],
155
+ )
156
+
157
+ output_text_sq.change(
158
+ update_button_states_sq,
159
+ inputs=[input_text_sq, output_text_sq],
160
+ outputs=[generate_btn_sq, clear_btn_sq],
161
+ )
162
+
163
+ # Event handlers for button actions to process and clear text
164
+ generate_btn_sq.click(
165
+ fn=generate,
166
+ inputs=[
167
+ input_text_sq,
168
+ temperature_sq,
169
+ max_tokens_sq,
170
+ top_k_sq,
171
+ repetition_penalty_sq,
172
+ top_p_sq,
173
+ ],
174
+ outputs=output_text_sq,
175
+ )
176
+
177
+ clear_btn_sq.click(
178
+ fn=lambda: ("", ""),
179
+ inputs=None,
180
+ outputs=[input_text_sq, output_text_sq],
181
+ )
182
+
183
+ with gr.Column(visible=False) as formalizer_column:
184
+ input_text = gr.Textbox(
185
+ placeholder="Wpisz tekst tutaj...", label="Tw贸j tekst", lines=5
186
+ )
187
+ with gr.Row():
188
+ gr.Text(
189
+ "Wybierz styl tekstu:",
190
+ elem_id="style-label",
191
+ show_label=False,
192
+ elem_classes="same-height",
193
+ )
194
+ style_dropdown = gr.Dropdown(
195
+ choices=["Formalny", "Nieformalny", "Neutralny"],
196
+ elem_id="style-dropdown",
197
+ show_label=False,
198
+ elem_classes="same-height",
199
+ )
200
+ generate_btn = gr.Button(
201
+ "Generuj",
202
+ interactive=False,
203
+ elem_id="generate-btn",
204
+ elem_classes="same-height",
205
+ )
206
+ clear_btn = gr.Button(
207
+ "Wyczy艣膰",
208
+ interactive=False,
209
+ elem_id="clear-btn",
210
+ elem_classes="same-height",
211
+ )
212
+ output_text = gr.Textbox(label="Wynik", interactive=False)
213
+
214
+ # Mock processing function to simulate text formalization with a delay
215
+ def mock_processing_function(input_text):
216
+ import time
217
+
218
+ time.sleep(1) # Simulate processing delay
219
+ return input_text + " [Formalized]"
220
 
221
+ # Update button states based on input and output text changes for interactivity
222
+ def update_button_states(input_text, output_text):
223
+ return [
224
+ gr.update(interactive=bool(input_text)),
225
+ gr.update(interactive=bool(input_text or output_text)),
226
+ gr.update(interactive=bool(output_text)),
227
+ ]
228
+
229
+ input_text.change(
230
+ update_button_states,
231
+ inputs=[input_text, output_text],
232
+ outputs=[generate_btn, clear_btn],
233
+ )
234
+
235
+ output_text.change(
236
+ update_button_states,
237
+ inputs=[input_text, output_text],
238
+ outputs=[generate_btn, clear_btn],
239
+ )
240
+
241
+ # Event handlers for button actions to process and clear text
242
+ generate_btn.click(
243
+ fn=mock_processing_function, inputs=input_text, outputs=output_text
244
+ )
245
+
246
+ clear_btn.click(
247
+ fn=lambda: ("", ""), inputs=None, outputs=[input_text, output_text]
248
+ )
249
+
250
+ # Placeholder for Judge content column, initially hidden
251
+ with gr.Column(visible=False) as judge_column:
252
+ gr.Markdown("Judge tool content goes here.")
253
+
254
+ with gr.Accordion("鈿欙笍 Parametry", open=False):
255
+ temperature_jg = gr.Slider(0, 1, 0.3, step=0.1, label="Temperatura")
256
+ max_tokens_jg = gr.Slider(
257
+ 128, 4096, 1024, label="Maksymalna d艂ugo艣膰 odpowiedzi"
258
+ )
259
+ top_k_jg = gr.Slider(1, 80, 40, step=1, label="Top K")
260
+ repetition_penalty_jg = gr.Slider(
261
+ 0, 2, 1.1, step=0.1, label="Penalizacja powt贸rze艅"
262
+ )
263
+ top_p_jg = gr.Slider(0, 1, 0.95, step=0.05, label="Top P")
264
+
265
+ formalizer_btn.click(
266
+ lambda: switch_tool("Formalizer"),
267
+ outputs=[
268
+ formalizer_btn,
269
+ judge_btn,
270
+ simple_question_btn,
271
+ formalizer_column,
272
+ judge_column,
273
+ simple_question_column,
274
+ ],
275
+ )
276
+ judge_btn.click(
277
+ lambda: switch_tool("Judge"),
278
+ outputs=[
279
+ formalizer_btn,
280
+ judge_btn,
281
+ simple_question_btn,
282
+ formalizer_column,
283
+ judge_column,
284
+ simple_question_column,
285
+ ],
286
  )
287
+ simple_question_btn.click(
288
+ lambda: switch_tool("Simple Question"),
289
+ outputs=[
290
+ formalizer_btn,
291
+ judge_btn,
292
+ simple_question_btn,
293
+ formalizer_column,
294
+ judge_column,
295
+ simple_question_column,
296
+ ],
 
 
297
  )
298
+
299
+ formalizer_btn.click(
300
+ lambda: switch_tool("Formalizer"),
301
+ outputs=[
302
+ formalizer_btn,
303
+ judge_btn,
304
+ simple_question_btn,
305
+ formalizer_column,
306
+ judge_column,
307
+ simple_question_column,
308
+ ],
309
+ )
310
+ judge_btn.click(
311
+ lambda: switch_tool("Judge"),
312
+ outputs=[
313
+ formalizer_btn,
314
+ judge_btn,
315
+ simple_question_btn,
316
+ formalizer_column,
317
+ judge_column,
318
+ simple_question_column,
319
+ ],
320
+ )
321
+ simple_question_btn.click(
322
+ lambda: switch_tool("Simple Question"),
323
+ outputs=[
324
+ formalizer_btn,
325
+ judge_btn,
326
+ simple_question_btn,
327
+ formalizer_column,
328
+ judge_column,
329
+ simple_question_column,
330
+ ],
331
  )
 
332
 
333
+ demo.queue().launch()