Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -28,24 +28,14 @@ def infer(input_image, prompt, seed=42, randomize_seed=False, guidance_scale=2.5 
     | 
|
| 28 | 
         
             
                    seed = random.randint(0, MAX_SEED)
         
     | 
| 29 | 
         | 
| 30 | 
         
             
                input_image = input_image.convert("RGB")
         
     | 
| 31 | 
         
            -
                 
     | 
| 32 | 
         | 
| 33 | 
         
            -
                # if original_width >= original_height:
         
     | 
| 34 | 
         
            -
                #     new_width = 1024
         
     | 
| 35 | 
         
            -
                #     new_height = int(original_height * (new_width / original_width))
         
     | 
| 36 | 
         
            -
                #     new_height = round(new_height / 64) * 64
         
     | 
| 37 | 
         
            -
                # else:
         
     | 
| 38 | 
         
            -
                #     new_height = 1024
         
     | 
| 39 | 
         
            -
                #     new_width = int(original_width * (new_height / original_height))
         
     | 
| 40 | 
         
            -
                #     new_width = round(new_width / 64) * 64
         
     | 
| 41 | 
         
            -
                
         
     | 
| 42 | 
         
            -
                #input_image_resized = input_image.resize((new_width, new_height), Image.LANCZOS)
         
     | 
| 43 | 
         
             
                image = pipe(
         
     | 
| 44 | 
         
             
                    image=input_image, 
         
     | 
| 45 | 
         
            -
                    prompt= 
     | 
| 46 | 
         
             
                    guidance_scale=guidance_scale,
         
     | 
| 47 | 
         
            -
                     
     | 
| 48 | 
         
            -
                     
     | 
| 49 | 
         
             
                    generator=torch.Generator().manual_seed(seed),
         
     | 
| 50 | 
         
             
                ).images[0]
         
     | 
| 51 | 
         
             
                return image, seed, gr.update(visible=True)
         
     | 
| 
         @@ -60,18 +50,18 @@ css=""" 
     | 
|
| 60 | 
         
             
            with gr.Blocks(css=css) as demo:
         
     | 
| 61 | 
         | 
| 62 | 
         
             
                with gr.Column(elem_id="col-container"):
         
     | 
| 63 | 
         
            -
                    gr.Markdown(f"""# FLUX.1 Kontext [dev]
         
     | 
| 64 | 
         
             
                    """)
         
     | 
| 65 | 
         | 
| 66 | 
         
             
                    with gr.Row():
         
     | 
| 67 | 
         
             
                        with gr.Column():
         
     | 
| 68 | 
         
            -
                            input_image = gr.Image(label="Upload the image for  
     | 
| 69 | 
         
             
                            with gr.Row():
         
     | 
| 70 | 
         
             
                                prompt = gr.Text(
         
     | 
| 71 | 
         
             
                                    label="Prompt",
         
     | 
| 72 | 
         
             
                                    show_label=False,
         
     | 
| 73 | 
         
             
                                    max_lines=1,
         
     | 
| 74 | 
         
            -
                                    placeholder=" 
     | 
| 75 | 
         
             
                                    container=False,
         
     | 
| 76 | 
         
             
                                )
         
     | 
| 77 | 
         
             
                                run_button = gr.Button("Run", scale=0)
         
     | 
| 
         | 
|
| 28 | 
         
             
                    seed = random.randint(0, MAX_SEED)
         
     | 
| 29 | 
         | 
| 30 | 
         
             
                input_image = input_image.convert("RGB")
         
     | 
| 31 | 
         
            +
                prompt_with_template = f"hange the lighting conditions in this image and add {prompt}. Lighting determines how bright or dark different parts of the image appear, where shadows fall, and how colors look. When you relight an image, you're simulating what the photo would look like if it were taken under different lighting conditions."
         
     | 
| 32 | 
         | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 33 | 
         
             
                image = pipe(
         
     | 
| 34 | 
         
             
                    image=input_image, 
         
     | 
| 35 | 
         
            +
                    prompt=prompt_with_template,
         
     | 
| 36 | 
         
             
                    guidance_scale=guidance_scale,
         
     | 
| 37 | 
         
            +
                    width=input_image.size[0],
         
     | 
| 38 | 
         
            +
                    height=input_image.size[1],
         
     | 
| 39 | 
         
             
                    generator=torch.Generator().manual_seed(seed),
         
     | 
| 40 | 
         
             
                ).images[0]
         
     | 
| 41 | 
         
             
                return image, seed, gr.update(visible=True)
         
     | 
| 
         | 
|
| 50 | 
         
             
            with gr.Blocks(css=css) as demo:
         
     | 
| 51 | 
         | 
| 52 | 
         
             
                with gr.Column(elem_id="col-container"):
         
     | 
| 53 | 
         
            +
                    gr.Markdown(f"""# FLUX.1 Kontext [dev] Relight
         
     | 
| 54 | 
         
             
                    """)
         
     | 
| 55 | 
         | 
| 56 | 
         
             
                    with gr.Row():
         
     | 
| 57 | 
         
             
                        with gr.Column():
         
     | 
| 58 | 
         
            +
                            input_image = gr.Image(label="Upload the image for relighting", type="pil")
         
     | 
| 59 | 
         
             
                            with gr.Row():
         
     | 
| 60 | 
         
             
                                prompt = gr.Text(
         
     | 
| 61 | 
         
             
                                    label="Prompt",
         
     | 
| 62 | 
         
             
                                    show_label=False,
         
     | 
| 63 | 
         
             
                                    max_lines=1,
         
     | 
| 64 | 
         
            +
                                    placeholder="scifi RGB flowing, studio lighting",
         
     | 
| 65 | 
         
             
                                    container=False,
         
     | 
| 66 | 
         
             
                                )
         
     | 
| 67 | 
         
             
                                run_button = gr.Button("Run", scale=0)
         
     |