VictorSanh commited on
Commit
8eb2e22
1 Parent(s): fcb202b

Update app_dialogue.py

Browse files
Files changed (1) hide show
  1. app_dialogue.py +65 -57
app_dialogue.py CHANGED
@@ -358,13 +358,10 @@ def model_generation(
358
  if len(eos_tokens) > 0:
359
  eos_token_ids = []
360
  for eos_token in eos_tokens:
361
- tokenized_eos_token = tokenizer(eos_token, add_special_tokens=False).input_ids
362
- if len(tokenized_eos_token) > 1:
363
- raise ValueError(
364
- f"eos_tokens should be one token, here {eos_token} is {len(tokenized_eos_token)} tokens:"
365
- f" {tokenized_eos_token}"
366
- )
367
- eos_token_ids += tokenized_eos_token
368
 
369
  # Common parameters to all decoding strategies
370
  # This documentation is useful to read: https://huggingface.co/docs/transformers/main/en/generation_strategies
@@ -446,6 +443,11 @@ def model_generation(
446
 
447
 
448
  dope_callback = gr.CSVLogger()
 
 
 
 
 
449
  problematic_callback = gr.CSVLogger()
450
 
451
  textbox = gr.Textbox(
@@ -453,6 +455,7 @@ textbox = gr.Textbox(
453
  value="Describe the battle against the fierce dragons.",
454
  visible=True,
455
  container=False,
 
456
  )
457
  with gr.Blocks(title="IDEFICS-Chat", theme=gr.themes.Base()) as demo:
458
  gr.Markdown(
@@ -477,6 +480,7 @@ with gr.Blocks(title="IDEFICS-Chat", theme=gr.themes.Base()) as demo:
477
  interactive=True,
478
  show_label=False,
479
  container=False,
 
480
  )
481
  processor, tokenizer, model = load_processor_tokenizer_model(model_selector.value)
482
 
@@ -815,8 +819,9 @@ And so, the story of Mulan and Shrek's romance came to an end, leaving a lasting
815
 
816
  # Using Flagging for saving dope and problematic examples
817
  # Dope examples flagging
818
- dope_callback.setup(
819
  [
 
820
  textbox,
821
  chatbot,
822
  imagebox,
@@ -835,8 +840,9 @@ And so, the story of Mulan and Shrek's romance came to an end, leaving a lasting
835
  "gradio_dope_data_points"
836
  )
837
  dope_bttn.click(
838
- lambda *args: dope_callback.flag(args),
839
  [
 
840
  textbox,
841
  chatbot,
842
  imagebox,
@@ -858,6 +864,7 @@ And so, the story of Mulan and Shrek's romance came to an end, leaving a lasting
858
  # Problematic examples flagging
859
  problematic_callback.setup(
860
  [
 
861
  textbox,
862
  chatbot,
863
  imagebox,
@@ -878,6 +885,7 @@ And so, the story of Mulan and Shrek's romance came to an end, leaving a lasting
878
  problematic_bttn.click(
879
  lambda *args: problematic_callback.flag(args),
880
  [
 
881
  textbox,
882
  chatbot,
883
  imagebox,
@@ -912,53 +920,53 @@ And so, the story of Mulan and Shrek's romance came to an end, leaving a lasting
912
  gr.Examples(
913
  examples=[
914
  ["What are the armed baguettes guarding?", f"{examples_path}/example_images/baguettes_guarding_paris.png"],
915
- [
916
- "Can you tell me a very short story based on this image?",
917
- f"{examples_path}/example_images/chicken_on_money.png",
918
- ],
919
- ["Can you describe the image?", f"{examples_path}/example_images/bear_costume.png"],
920
- ["What is this animal and why is it unusual?", f"{examples_path}/example_images/blue_dog.png"],
921
- [
922
- "What is this object and do you think it is horrifying?",
923
- f"{examples_path}/example_images/can_horror.png",
924
- ],
925
- ["What is this sketch for? How would you make an argument to prove this sketch was made by Picasso himself?", f"{examples_path}/example_images/cat_sketch.png"],
926
- ["Which celebrity does this claymation figure look like?", f"{examples_path}/example_images/kanye.jpg"],
927
- [
928
- "Which famous person does the person in the image look like? Could you craft an engaging narrative featuring this character from the image as the main protagonist?",
929
- f"{examples_path}/example_images/obama-harry-potter.jpg",
930
- ],
931
- [
932
- "Is there a celebrity look-alike in this image? What is happening to the person?",
933
- f"{examples_path}/example_images/ryan-reynolds-borg.jpg",
934
- ],
935
- ["Can you describe this image in details please?", f"{examples_path}/example_images/dragons_playing.png"],
936
- ["What can you tell me about the cap in this image?", f"{examples_path}/example_images/ironman_cap.png"],
937
- [
938
- "Can you write an advertisement for Coca-Cola based on this image?",
939
- f"{examples_path}/example_images/polar_bear_coke.png",
940
- ],
941
- [
942
- "What is the rabbit doing in this image? Do you think this image is real?",
943
- f"{examples_path}/example_images/rabbit_force.png",
944
- ],
945
- ["What is happening in this image and why is it unusual?", f"{examples_path}/example_images/ramen.png"],
946
- [
947
- "What I should look most forward to when I visit this place?",
948
- f"{examples_path}/example_images/tree_fortress.jpg",
949
- ],
950
- ["Who is the person in the image and what is he doing?", f"{examples_path}/example_images/tom-cruise-astronaut-pegasus.jpg"],
951
- [
952
- "What is happening in this image? Which famous personality does this person in center looks like?",
953
- f"{examples_path}/example_images/gandhi_selfie.jpg",
954
- ],
955
- [
956
- (
957
- "<fake_token_around_image><image:https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/stable-diffusion-xl-coreml/a_high_quality_photo_of_a_surfing_dog.7667.final_float16_original.jpg><fake_token_around_image>What"
958
- " do you think the dog is doing and is it unusual?"
959
- ),
960
- None,
961
- ],
962
  ],
963
  inputs=[textbox, imagebox],
964
  outputs=[textbox, imagebox, chatbot],
@@ -969,4 +977,4 @@ And so, the story of Mulan and Shrek's romance came to an end, leaving a lasting
969
  )
970
 
971
  demo.queue()
972
- demo.launch()
 
358
  if len(eos_tokens) > 0:
359
  eos_token_ids = []
360
  for eos_token in eos_tokens:
361
+ tokenized_eos_token = tokenizer.convert_tokens_to_ids(eos_token)
362
+ if tokenized_eos_token == 0: # <unk> with our llama tokenizer
363
+ raise ValueError(f"Unknown tokens specified for exit condition.")
364
+ eos_token_ids += [tokenized_eos_token]
 
 
 
365
 
366
  # Common parameters to all decoding strategies
367
  # This documentation is useful to read: https://huggingface.co/docs/transformers/main/en/generation_strategies
 
443
 
444
 
445
  dope_callback = gr.CSVLogger()
446
+ dope_hf_callback = gr.HuggingFaceDatasetSaver(
447
+ hf_token=os.getenv("HF_AUTH_TOKEN"),
448
+ dataset_name="HuggingFaceM4/gradio_dope_data_points",
449
+ private=True,
450
+ )
451
  problematic_callback = gr.CSVLogger()
452
 
453
  textbox = gr.Textbox(
 
455
  value="Describe the battle against the fierce dragons.",
456
  visible=True,
457
  container=False,
458
+ label="Text input",
459
  )
460
  with gr.Blocks(title="IDEFICS-Chat", theme=gr.themes.Base()) as demo:
461
  gr.Markdown(
 
480
  interactive=True,
481
  show_label=False,
482
  container=False,
483
+ label="Model"
484
  )
485
  processor, tokenizer, model = load_processor_tokenizer_model(model_selector.value)
486
 
 
819
 
820
  # Using Flagging for saving dope and problematic examples
821
  # Dope examples flagging
822
+ dope_hf_callback.setup(
823
  [
824
+ model_selector,
825
  textbox,
826
  chatbot,
827
  imagebox,
 
840
  "gradio_dope_data_points"
841
  )
842
  dope_bttn.click(
843
+ lambda *args: dope_hf_callback.flag(args),
844
  [
845
+ model_selector,
846
  textbox,
847
  chatbot,
848
  imagebox,
 
864
  # Problematic examples flagging
865
  problematic_callback.setup(
866
  [
867
+ model_selector,
868
  textbox,
869
  chatbot,
870
  imagebox,
 
885
  problematic_bttn.click(
886
  lambda *args: problematic_callback.flag(args),
887
  [
888
+ model_selector,
889
  textbox,
890
  chatbot,
891
  imagebox,
 
920
  gr.Examples(
921
  examples=[
922
  ["What are the armed baguettes guarding?", f"{examples_path}/example_images/baguettes_guarding_paris.png"],
923
+ # [
924
+ # "Can you tell me a very short story based on this image?",
925
+ # f"{examples_path}/example_images/chicken_on_money.png",
926
+ # ],
927
+ # ["Can you describe the image?", f"{examples_path}/example_images/bear_costume.png"],
928
+ # ["What is this animal and why is it unusual?", f"{examples_path}/example_images/blue_dog.png"],
929
+ # [
930
+ # "What is this object and do you think it is horrifying?",
931
+ # f"{examples_path}/example_images/can_horror.png",
932
+ # ],
933
+ # ["What is this sketch for? How would you make an argument to prove this sketch was made by Picasso himself?", f"{examples_path}/example_images/cat_sketch.png"],
934
+ # ["Which celebrity does this claymation figure look like?", f"{examples_path}/example_images/kanye.jpg"],
935
+ # [
936
+ # "Which famous person does the person in the image look like? Could you craft an engaging narrative featuring this character from the image as the main protagonist?",
937
+ # f"{examples_path}/example_images/obama-harry-potter.jpg",
938
+ # ],
939
+ # [
940
+ # "Is there a celebrity look-alike in this image? What is happening to the person?",
941
+ # f"{examples_path}/example_images/ryan-reynolds-borg.jpg",
942
+ # ],
943
+ # ["Can you describe this image in details please?", f"{examples_path}/example_images/dragons_playing.png"],
944
+ # ["What can you tell me about the cap in this image?", f"{examples_path}/example_images/ironman_cap.png"],
945
+ # [
946
+ # "Can you write an advertisement for Coca-Cola based on this image?",
947
+ # f"{examples_path}/example_images/polar_bear_coke.png",
948
+ # ],
949
+ # [
950
+ # "What is the rabbit doing in this image? Do you think this image is real?",
951
+ # f"{examples_path}/example_images/rabbit_force.png",
952
+ # ],
953
+ # ["What is happening in this image and why is it unusual?", f"{examples_path}/example_images/ramen.png"],
954
+ # [
955
+ # "What I should look most forward to when I visit this place?",
956
+ # f"{examples_path}/example_images/tree_fortress.jpg",
957
+ # ],
958
+ # ["Who is the person in the image and what is he doing?", f"{examples_path}/example_images/tom-cruise-astronaut-pegasus.jpg"],
959
+ # [
960
+ # "What is happening in this image? Which famous personality does this person in center looks like?",
961
+ # f"{examples_path}/example_images/gandhi_selfie.jpg",
962
+ # ],
963
+ # [
964
+ # (
965
+ # "<fake_token_around_image><image:https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/stable-diffusion-xl-coreml/a_high_quality_photo_of_a_surfing_dog.7667.final_float16_original.jpg><fake_token_around_image>What"
966
+ # " do you think the dog is doing and is it unusual?"
967
+ # ),
968
+ # None,
969
+ # ],
970
  ],
971
  inputs=[textbox, imagebox],
972
  outputs=[textbox, imagebox, chatbot],
 
977
  )
978
 
979
  demo.queue()
980
+ demo.launch(share=False)