Spaces:
Paused
Paused
Commit ·
b64eca0
1
Parent(s): 575f433
change guessing to use buttons
Browse files123456789121 unmodified lines1311321331341351366 unmodified lines14314414514614714814915068 unmodified lines21922022122222322422522622722822913 unmodified lines2432442452462472482492502512522532542552562572582592602612624 unmodified lines267268269270271272273274275276277278279280281282283284285286import torchimport gradio as grfrom diffusers import FluxPipeline, FluxTransformer2DModelfrom diffusers import BitsAndBytesConfig as DiffusersBitsAndBytesConfigfrom transformers import T5EncoderModelfrom transformers import BitsAndBytesConfig as TransformersBitsAndBytesConfigimport gcimport randomfrom PIL import Image121 unmodified linescurrent_pipe = None # Keep track of the current pipe for cleanupfor i, (label, load_func) in enumerate(model_configs):progress(i / len(model_configs), desc=f"Loading {label} model...")print(f"\n--- Loading {label} Model ---")6 unmodified linesprogress((i + 0.5) / len(model_configs), desc=f"Generating with {label} model...")print(f"--- Generating with {label} Model ---")gen_start_time = time.time()image_list = current_pipe(**pipe_kwargs, generator=torch.manual_seed(GENERATION_SEED)).imagesimage = image_list[0]gen_end_time = time.time()results.append({"label": label, "image": image})print(f"--- Finished Generation with {label} Model in {gen_end_time - gen_start_time:.2f} seconds ---")68 unmodified linesgr.Markdown("Compare the original FLUX.1-dev (BF16) model against a quantized version (4-bit or 8-bit). ""Enter a prompt, choose the quantization method, and generate two images. ""The images will be shuffled. Can you guess which one used quantization?")with gr.Row():prompt_input = gr.Textbox(label="Enter Prompt", placeholder="e.g., A photorealistic portrait of an astronaut on Mars", scale=3)quantization_choice_radio = gr.Radio(choices=["8-bit", "4-bit"],label="Select Quantization",13 unmodified linesgr.Markdown("### Which image used the selected quantization method?")with gr.Row():# Centered guess radio and submit buttonwith gr.Column(scale=1): # Dummy column for spacingpasswith gr.Column(scale=2): # Column for the radio buttonguess_radio = gr.Radio(choices=[],label="Your Guess",info="Select the image you believe was generated with the quantized model.",interactive=False # Disabled until images are generated)with gr.Column(scale=1): # Column for the buttonsubmit_guess_button = gr.Button("Submit Guess")with gr.Column(scale=1): # Dummy column for spacingpassfeedback_box = gr.Textbox(label="Feedback", interactive=False, lines=1)4 unmodified linesgenerate_button.click(fn=generate_images,inputs=[prompt_input, quantization_choice_radio],outputs=[output_gallery, correct_mapping_state, feedback_box, guess_radio]).then(lambda: "", # Clear feedback box on new generationoutputs=[feedback_box])submit_guess_button.click(fn=check_guess,inputs=[guess_radio, correct_mapping_state], # Pass the selected guess and the stateoutputs=[feedback_box])if __name__ == "__main__":# queue()# demo.queue().launch()demo.launch(share=True)123456121 unmodified lines1281291301311321331341351366 unmodified lines14314414514614714814915015168 unmodified lines22022122222322422522622722822923013 unmodified lines2442452462472482492502514 unmodified lines256257258259260261262263264265266267268269270271272273import torchimport gradio as grfrom diffusers import FluxPipeline, FluxTransformer2DModelimport gcimport randomfrom PIL import Image121 unmodified linescurrent_pipe = None # Keep track of the current pipe for cleanupseed = random.getrandbits(64)print(f"Using seed: {seed}")for i, (label, load_func) in enumerate(model_configs):progress(i / len(model_configs), desc=f"Loading {label} model...")print(f"\n--- Loading {label} Model ---")6 unmodified linesprogress((i + 0.5) / len(model_configs), desc=f"Generating with {label} model...")print(f"--- Generating with {label} Model ---")gen_start_time = time.time()image_list = current_pipe(**pipe_kwargs, generator=torch.manual_seed(seed)).imagesimage = image_list[0]# image.save(f"{load_start_time}.png")gen_end_time = time.time()results.append({"label": label, "image": image})print(f"--- Finished Generation with {label} Model in {gen_end_time - gen_start_time:.2f} seconds ---")68 unmodified linesgr.Markdown("Compare the original FLUX.1-dev (BF16) model against a quantized version (4-bit or 8-bit). ""Enter a prompt, choose the quantization method, and generate two images. ""The images will be shuffled, can you spot which one was quantized?")with gr.Row():prompt_input = gr.Textbox(label="Enter Prompt", scale=3)quantization_choice_radio = gr.Radio(choices=["8-bit", "4-bit"],label="Select Quantization",13 unmodified linesgr.Markdown("### Which image used the selected quantization method?")with gr.Row():image1_btn = gr.Button("Image 1")image2_btn = gr.Button("Image 2")feedback_box = gr.Textbox(label="Feedback", interactive=False, lines=1)4 unmodified linesgenerate_button.click(fn=generate_images,inputs=[prompt_input, quantization_choice_radio],outputs=[output_gallery, correct_mapping_state],).then(lambda: "", outputs=[feedback_box]) # clear feedback on new run# helper wrappers so we can supply the fixed choice stringdef choose_img1(mapping):return check_guess("Image 1", mapping)def choose_img2(mapping):return check_guess("Image 2", mapping)image1_btn.click(choose_img1, inputs=[correct_mapping_state], outputs=[feedback_box])image2_btn.click(choose_img2, inputs=[correct_mapping_state], outputs=[feedback_box])if __name__ == "__main__":demo.launch(share=True)demo.launch()
app.py+20-33