Spaces:
Running
Running
Ehssan
commited on
Commit
·
3a0c064
1
Parent(s):
1e859b4
Use Examples class for textbox examples
Browse files
app.py
CHANGED
@@ -273,18 +273,27 @@ def main() -> None:
|
|
273 |
gr.Markdown("### Use Case")
|
274 |
use_case = gr.Textbox(
|
275 |
show_label=False,
|
276 |
-
|
277 |
autofocus=True,
|
278 |
)
|
279 |
label_boxes = gr.State([])
|
280 |
-
gr.Markdown(
|
|
|
|
|
281 |
with gr.Row():
|
282 |
new_label = gr.Textbox(
|
283 |
show_label=False,
|
284 |
-
info="Example. polite: Text is considerate and shows respect and good manners, often including courteous phrases and a friendly tone.",
|
285 |
-
placeholder="Use a colon to separate each label and its description.",
|
286 |
)
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
|
289 |
def add_item(
|
290 |
label_boxes: List[Dict[str, str]], new_content: str
|
@@ -318,13 +327,12 @@ def main() -> None:
|
|
318 |
Args:
|
319 |
box_list (List[Dict[str, str]]): A list containing dictionaries representing the categories to render.
|
320 |
"""
|
321 |
-
with gr.Accordion(
|
322 |
-
f"Number of Entered Labels ({len(box_list)})"
|
323 |
-
):
|
324 |
for box in box_list:
|
325 |
with gr.Row():
|
326 |
gr.Textbox(
|
327 |
box["content"],
|
|
|
328 |
show_label=False,
|
329 |
container=False,
|
330 |
)
|
@@ -350,16 +358,21 @@ def main() -> None:
|
|
350 |
delete_button.click(delete, None, [label_boxes])
|
351 |
|
352 |
category_boxes = gr.State([])
|
353 |
-
gr.Markdown(
|
|
|
|
|
354 |
with gr.Row():
|
355 |
-
new_category = gr.Textbox(
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
"
|
|
|
362 |
)
|
|
|
|
|
363 |
add_category_button.click(
|
364 |
add_item,
|
365 |
[category_boxes, new_category],
|
@@ -374,9 +387,7 @@ def main() -> None:
|
|
374 |
Args:
|
375 |
box_list (List[Dict[str, str]]): A list containing dictionaries representing the categories to render.
|
376 |
"""
|
377 |
-
with gr.Accordion(
|
378 |
-
f"Number of Entered Categories ({len(box_list)})"
|
379 |
-
):
|
380 |
for box in box_list:
|
381 |
with gr.Row():
|
382 |
gr.Textbox(
|
@@ -384,9 +395,9 @@ def main() -> None:
|
|
384 |
show_label=False,
|
385 |
container=False,
|
386 |
)
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
|
391 |
def delete(
|
392 |
box: Dict[str, str] = box,
|
@@ -406,20 +417,36 @@ def main() -> None:
|
|
406 |
delete_button.click(delete, None, [category_boxes])
|
407 |
|
408 |
gr.Markdown(
|
409 |
-
"### Guiding Examples"
|
410 |
)
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
|
|
|
|
|
|
|
|
415 |
CATEGORY: food and drink
|
416 |
TYPE: cafe
|
417 |
OUTPUT: Thank you for visiting! While we prepare your coffee, feel free to relax or browse our selection of pastries. Let us know if we can make your day even better!
|
418 |
-
REASONING: This text is polite because it expresses gratitude and encourages the customer to feel at ease with a welcoming tone. Phrases like "Let us know if we can make your day even better" show warmth and consideration, enhancing the customer experience.
|
419 |
-
|
420 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
421 |
)
|
422 |
-
gr.Markdown("### Language Model")
|
423 |
model = gr.Dropdown(
|
424 |
label="Model",
|
425 |
choices=[
|
@@ -430,7 +457,7 @@ REASONING: This text is polite because it expresses gratitude and encourages the
|
|
430 |
value="google/gemma-3-1b-it",
|
431 |
)
|
432 |
max_new_tokens = gr.Number(
|
433 |
-
label="
|
434 |
)
|
435 |
token = gr.Textbox(
|
436 |
label="Hugging Face Token",
|
@@ -443,31 +470,39 @@ REASONING: This text is polite because it expresses gratitude and encourages the
|
|
443 |
elem_classes="text-center",
|
444 |
)
|
445 |
gr.Markdown("### Status")
|
446 |
-
status = gr.Textbox(
|
447 |
-
gr.Markdown(
|
|
|
|
|
448 |
sample_size = gr.Number(label="Sample Size", value=1, minimum=1)
|
449 |
save_reasoning = gr.Checkbox(label="Save Reasoning", value=True)
|
450 |
-
generate_button = gr.Button(
|
451 |
-
"Generate!", interactive=False, elem_classes="btn"
|
452 |
-
)
|
453 |
-
download_button = gr.Button(
|
454 |
-
"Download CSV", interactive=False, elem_classes="btn"
|
455 |
-
)
|
456 |
-
file_output = gr.File(label="Download!", visible=False)
|
457 |
repo_id = gr.Textbox(
|
458 |
-
label="Hugging Face Repo ID",
|
459 |
placeholder="your-username/your-repo-name",
|
460 |
)
|
461 |
is_public_repo = gr.Checkbox(
|
462 |
label="Make Repository Public", value=False
|
463 |
)
|
464 |
-
|
465 |
-
|
466 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
467 |
gr.Markdown(
|
468 |
"### Sample Output",
|
469 |
)
|
470 |
-
dataset = load_dataset(
|
|
|
|
|
|
|
471 |
dataset = dataset["validation"].to_pandas().sample(n=5)
|
472 |
|
473 |
dataframe = gr.Dataframe(value=dataset, show_label=False)
|
@@ -653,7 +688,7 @@ REASONING: This text is polite because it expresses gratitude and encourages the
|
|
653 |
This synthetic data generator, part of Intel's [Polite Guard](https://huggingface.co/Intel/polite-guard) project, utilizes a specified language model to generate synthetic data for a given use case.
|
654 |
If you find this project valuable, please consider giving it a ❤️ on Hugging Face and sharing it with your network.
|
655 |
Visit
|
656 |
-
- [Polite Guard GitHub repository](https://github.com/intel/polite-guard) for the source code that you can run through the command line,
|
657 |
- [Synthetic Data Generation with Language Models: A Practical Guide](https://medium.com/p/0ff98eb226a1) to learn more about the implementation of this data generator, and
|
658 |
- [Polite Guard Dataset](https://huggingface.co/datasets/Intel/polite-guard) for an example of a dataset generated using this data generator.
|
659 |
|
|
|
273 |
gr.Markdown("### Use Case")
|
274 |
use_case = gr.Textbox(
|
275 |
show_label=False,
|
276 |
+
placeholder="Describe your use case (e.g., customer service).",
|
277 |
autofocus=True,
|
278 |
)
|
279 |
label_boxes = gr.State([])
|
280 |
+
gr.Markdown(
|
281 |
+
"### Labels\nUse a colon to separate each label and its description as in 'label: description.'"
|
282 |
+
)
|
283 |
with gr.Row():
|
284 |
new_label = gr.Textbox(
|
285 |
show_label=False,
|
|
|
|
|
286 |
)
|
287 |
+
gr.Examples(
|
288 |
+
examples=[
|
289 |
+
"polite: Text is considerate and shows respect and good manners, often including courteous phrases and a friendly tone.",
|
290 |
+
"somewhat polite: Text is generally respectful but lacks warmth or formality, communicating with a decent level of courtesy.",
|
291 |
+
],
|
292 |
+
example_labels=["polite", "somewhat polite"],
|
293 |
+
inputs=new_label,
|
294 |
+
)
|
295 |
+
|
296 |
+
add_label_button = gr.Button("Save Label", elem_classes="btn")
|
297 |
|
298 |
def add_item(
|
299 |
label_boxes: List[Dict[str, str]], new_content: str
|
|
|
327 |
Args:
|
328 |
box_list (List[Dict[str, str]]): A list containing dictionaries representing the categories to render.
|
329 |
"""
|
330 |
+
with gr.Accordion(f"Saved Labels ({len(box_list)})"):
|
|
|
|
|
331 |
for box in box_list:
|
332 |
with gr.Row():
|
333 |
gr.Textbox(
|
334 |
box["content"],
|
335 |
+
lines=2,
|
336 |
show_label=False,
|
337 |
container=False,
|
338 |
)
|
|
|
358 |
delete_button.click(delete, None, [label_boxes])
|
359 |
|
360 |
category_boxes = gr.State([])
|
361 |
+
gr.Markdown(
|
362 |
+
"### Categories\nUse a colon to separate each category and its subcategories as in 'category: type1, type2.'"
|
363 |
+
)
|
364 |
with gr.Row():
|
365 |
+
new_category = gr.Textbox(show_label=False)
|
366 |
+
gr.Examples(
|
367 |
+
examples=[
|
368 |
+
"travel: hotel, airline, train",
|
369 |
+
"finance: fees and charges, credit",
|
370 |
+
],
|
371 |
+
example_labels=["travel", "finance"],
|
372 |
+
inputs=new_category,
|
373 |
)
|
374 |
+
|
375 |
+
add_category_button = gr.Button("Save Category", elem_classes="btn")
|
376 |
add_category_button.click(
|
377 |
add_item,
|
378 |
[category_boxes, new_category],
|
|
|
387 |
Args:
|
388 |
box_list (List[Dict[str, str]]): A list containing dictionaries representing the categories to render.
|
389 |
"""
|
390 |
+
with gr.Accordion(f"Saved Categories ({len(box_list)})"):
|
|
|
|
|
391 |
for box in box_list:
|
392 |
with gr.Row():
|
393 |
gr.Textbox(
|
|
|
395 |
show_label=False,
|
396 |
container=False,
|
397 |
)
|
398 |
+
delete_button = gr.Button(
|
399 |
+
"Delete", scale=0, variant="stop"
|
400 |
+
)
|
401 |
|
402 |
def delete(
|
403 |
box: Dict[str, str] = box,
|
|
|
417 |
delete_button.click(delete, None, [category_boxes])
|
418 |
|
419 |
gr.Markdown(
|
420 |
+
"### Guiding Examples\nInclude all examples in this box. For each example, provide a LABEL, CATEGORY, TYPE, OUTPUT, and REASONING."
|
421 |
)
|
422 |
+
with gr.Row():
|
423 |
+
prompt_examples = gr.Textbox(
|
424 |
+
show_label=False,
|
425 |
+
)
|
426 |
+
gr.Examples(
|
427 |
+
label="Example",
|
428 |
+
examples=[
|
429 |
+
"""LABEL: polite
|
430 |
CATEGORY: food and drink
|
431 |
TYPE: cafe
|
432 |
OUTPUT: Thank you for visiting! While we prepare your coffee, feel free to relax or browse our selection of pastries. Let us know if we can make your day even better!
|
433 |
+
REASONING: This text is polite because it expresses gratitude and encourages the customer to feel at ease with a welcoming tone. Phrases like "Let us know if we can make your day even better" show warmth and consideration, enhancing the customer experience.
|
434 |
+
|
435 |
+
LABEL: somewhat polite
|
436 |
+
CATEGORY: travel
|
437 |
+
TYPE: train
|
438 |
+
OUTPUT: I understand your concern about your booking, and I'll check what options we have for you.
|
439 |
+
REASONING: This text would be classified as "somewhat polite." The acknowledgment of the customer's concern shows a basic level of respect. The sentence is direct and lacks additional warmth or formality, but it communicates a willingness to help. The use of "I'll check" is a straightforward commitment to action without additional courteous phrases that would make it fully polite.
|
440 |
+
"""
|
441 |
+
],
|
442 |
+
example_labels=["polite and somewhat polite"],
|
443 |
+
inputs=prompt_examples,
|
444 |
+
)
|
445 |
+
|
446 |
+
gr.Markdown(
|
447 |
+
"""### Language Model
|
448 |
+
Visit [Llama 3.2](https://huggingface.co/meta-llama/Llama-3.2-3B-Instruct) and [Gemma 3](https://huggingface.co/google/gemma-3-1b-it), and submit an access request for these gated Hugging Face repositories."""
|
449 |
)
|
|
|
450 |
model = gr.Dropdown(
|
451 |
label="Model",
|
452 |
choices=[
|
|
|
457 |
value="google/gemma-3-1b-it",
|
458 |
)
|
459 |
max_new_tokens = gr.Number(
|
460 |
+
label="Maximum Number of New Tokens", value=256, minimum=64
|
461 |
)
|
462 |
token = gr.Textbox(
|
463 |
label="Hugging Face Token",
|
|
|
470 |
elem_classes="text-center",
|
471 |
)
|
472 |
gr.Markdown("### Status")
|
473 |
+
status = gr.Textbox(show_label=False)
|
474 |
+
gr.Markdown(
|
475 |
+
"### Actions\nEnter the number of rows for the generated dataset, and optionally a Hugging Face repo ID."
|
476 |
+
)
|
477 |
sample_size = gr.Number(label="Sample Size", value=1, minimum=1)
|
478 |
save_reasoning = gr.Checkbox(label="Save Reasoning", value=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
479 |
repo_id = gr.Textbox(
|
480 |
+
label="Hugging Face Repo ID (Optional)",
|
481 |
placeholder="your-username/your-repo-name",
|
482 |
)
|
483 |
is_public_repo = gr.Checkbox(
|
484 |
label="Make Repository Public", value=False
|
485 |
)
|
486 |
+
with gr.Row():
|
487 |
+
generate_button = gr.Button(
|
488 |
+
"Generate", interactive=False, elem_classes="btn"
|
489 |
+
)
|
490 |
+
download_button = gr.Button(
|
491 |
+
"Download", interactive=False, elem_classes="btn"
|
492 |
+
)
|
493 |
+
push_button = gr.Button(
|
494 |
+
"Push to 🤗",
|
495 |
+
interactive=False,
|
496 |
+
variant="huggingface",
|
497 |
+
)
|
498 |
+
file_output = gr.File(label="Download", visible=False)
|
499 |
gr.Markdown(
|
500 |
"### Sample Output",
|
501 |
)
|
502 |
+
dataset = load_dataset(
|
503 |
+
"intel/polite-guard",
|
504 |
+
data_files={"validation": "data/validation/val_cot.csv"},
|
505 |
+
)
|
506 |
dataset = dataset["validation"].to_pandas().sample(n=5)
|
507 |
|
508 |
dataframe = gr.Dataframe(value=dataset, show_label=False)
|
|
|
688 |
This synthetic data generator, part of Intel's [Polite Guard](https://huggingface.co/Intel/polite-guard) project, utilizes a specified language model to generate synthetic data for a given use case.
|
689 |
If you find this project valuable, please consider giving it a ❤️ on Hugging Face and sharing it with your network.
|
690 |
Visit
|
691 |
+
- [Polite Guard GitHub repository](https://github.com/intel/polite-guard) for the source code that you can run through the command line on an AI PC or [Intel Tiber AI Cloud](https://ai.cloud.intel.com/),
|
692 |
- [Synthetic Data Generation with Language Models: A Practical Guide](https://medium.com/p/0ff98eb226a1) to learn more about the implementation of this data generator, and
|
693 |
- [Polite Guard Dataset](https://huggingface.co/datasets/Intel/polite-guard) for an example of a dataset generated using this data generator.
|
694 |
|