ysharma HF staff commited on
Commit
4b6d6f3
1 Parent(s): 050d259

Update app_dialogue.py

Browse files
Files changed (1) hide show
  1. app_dialogue.py +26 -37
app_dialogue.py CHANGED
@@ -69,6 +69,12 @@ from PIL import Image
69
  import tempfile
70
 
71
 
 
 
 
 
 
 
72
  def convert_to_rgb_pil(image):
73
  """
74
  Convert a PIL Image object to RGB mode and save it locally.
@@ -553,36 +559,12 @@ textbox = gr.Textbox(
553
  label="Text input",
554
  )
555
 
556
- css_not = """
557
- #chatbot {
558
- background-image: url('https://e7.pngegg.com/pngimages/393/627/png-clipart-obelix-asterix-cartoon-comic-book-comics-asterix-and-obelix-comics-food.png');
559
- background-repeat: repeat;
560
- }
561
- """
562
-
563
- css = """
564
- #chatbot {
565
- background-image: url('https://huggingface.co/spaces/ysharma/m4-dialogue_copy4/resolve/main/idefics_720.png');
566
- background-repeat: repeat;
567
- }
568
- """
569
- css1 = """
570
- #chatbot {
571
- background-image: url('https://huggingface.co/spaces/ysharma/m4-dialogue_copy4/resolve/main/idefics_720_1.png');
572
- background-repeat: repeat;
573
- }
574
- """
575
  css2 = """
576
  #chatbot {
577
  background-image: url('https://huggingface.co/spaces/ysharma/m4-dialogue_copy4/resolve/main/idefics_720_2.png');
578
  background-repeat: repeat;}
579
  """
580
- css3 = """
581
- #chatbot {
582
- background-image: url('https://huggingface.co/spaces/ysharma/m4-dialogue_copy4/resolve/main/idefics_720_3.png');
583
- background-repeat: repeat;
584
- }
585
- """
586
 
587
  with gr.Blocks(title="IDEFICS-Chat", theme=gr.themes.Base(), css=css2) as demo:
588
  gr.Markdown(
@@ -611,7 +593,7 @@ with gr.Blocks(title="IDEFICS-Chat", theme=gr.themes.Base(), css=css2) as demo:
611
  )
612
  processor, tokenizer, model = load_processor_tokenizer_model(model_selector.value)
613
 
614
- imagebox = gr.Image(type="filepath", label="Image input")
615
 
616
  with gr.Accordion("Advanced parameters", open=False, visible=True) as parameter_row:
617
  max_new_tokens = gr.Slider(
@@ -802,17 +784,22 @@ And so, the story of Mulan and Shrek's romance came to an end, leaving a lasting
802
  ],
803
  ],
804
  )
805
- with gr.Row():
806
- with gr.Column(scale=8):
807
- textbox.render()
808
- with gr.Column(scale=1, min_width=60):
809
- submit_btn = gr.Button(value="Submit", visible=True)
810
- with gr.Column(scale=1, min_width=20):
811
- clear_btn = gr.ClearButton([textbox, chatbot])
812
- with gr.Column(scale=1, min_width=15):
813
- dope_bttn = gr.Button("Dope🔥")
814
- with gr.Column(scale=1, min_width=15):
815
- problematic_bttn = gr.Button("Problematic😬")
 
 
 
 
 
816
 
817
  def model_inference(
818
  user_prompt_str,
@@ -926,6 +913,8 @@ And so, the story of Mulan and Shrek's romance came to an end, leaving a lasting
926
  ],
927
  )
928
 
 
 
929
  # Using Flagging for saving dope and problematic examples
930
  # Dope examples flagging
931
  dope_hf_callback.setup(
 
69
  import tempfile
70
 
71
 
72
+ def add_file(file):
73
+ #history = history + [((file.name,), None)]
74
+ return file.name
75
+ #return history
76
+
77
+
78
  def convert_to_rgb_pil(image):
79
  """
80
  Convert a PIL Image object to RGB mode and save it locally.
 
559
  label="Text input",
560
  )
561
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
562
  css2 = """
563
  #chatbot {
564
  background-image: url('https://huggingface.co/spaces/ysharma/m4-dialogue_copy4/resolve/main/idefics_720_2.png');
565
  background-repeat: repeat;}
566
  """
567
+
 
 
 
 
 
568
 
569
  with gr.Blocks(title="IDEFICS-Chat", theme=gr.themes.Base(), css=css2) as demo:
570
  gr.Markdown(
 
593
  )
594
  processor, tokenizer, model = load_processor_tokenizer_model(model_selector.value)
595
 
596
+ imagebox = gr.Image(type="filepath", label="Image input", visible=False)
597
 
598
  with gr.Accordion("Advanced parameters", open=False, visible=True) as parameter_row:
599
  max_new_tokens = gr.Slider(
 
784
  ],
785
  ],
786
  )
787
+ with gr.Group():
788
+ with gr.Row():
789
+ with gr.Column(scale=7):
790
+ textbox.render()
791
+ with gr.Column(scale=1, min_width=80):
792
+ submit_btn = gr.Button(value="Submit", visible=True)
793
+ with gr.Column(scale=1, min_width=10):
794
+ clear_btn = gr.ClearButton([textbox, chatbot])
795
+ with gr.Column(scale=1, min_width=10):
796
+ upload_btn = gr.UploadButton("📁", file_types=["image"])
797
+ with gr.Group():
798
+ with gr.Row():
799
+ with gr.Column(scale=1, min_width=50):
800
+ dope_bttn = gr.Button("Dope🔥")
801
+ with gr.Column(scale=1, min_width=50):
802
+ problematic_bttn = gr.Button("Problematic😬")
803
 
804
  def model_inference(
805
  user_prompt_str,
 
913
  ],
914
  )
915
 
916
+ upload_btn.upload(add_file, [btn], [imagebox], queue=False)
917
+
918
  # Using Flagging for saving dope and problematic examples
919
  # Dope examples flagging
920
  dope_hf_callback.setup(