brennonatal commited on
Commit
caea7c0
1 Parent(s): b375830

inference api

Browse files
Files changed (4) hide show
  1. README.md +1 -9
  2. app.py +0 -105
  3. diffusion_pytorch_model.safetensors +0 -3
  4. requirements.txt +0 -5
README.md CHANGED
@@ -1,12 +1,4 @@
1
  ---
2
- title: flux-controlnet-upscaler
3
- emoji: 🐳
4
- colorFrom: blue
5
- colorTo: green
6
- sdk: gradio
7
- sdk_version: 5.1.0
8
- app_file: app.py
9
- pinned: false
10
  base_model:
11
  - black-forest-labs/FLUX.1-dev
12
  library_name: diffusers
@@ -14,7 +6,7 @@ license: other
14
  license_name: flux-1-dev-non-commercial-license
15
  license_link: https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md
16
  pipeline_tag: image-to-image
17
- inference: False
18
  tags:
19
  - ControlNet
20
  - super-resolution
 
1
  ---
 
 
 
 
 
 
 
 
2
  base_model:
3
  - black-forest-labs/FLUX.1-dev
4
  library_name: diffusers
 
6
  license_name: flux-1-dev-non-commercial-license
7
  license_link: https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md
8
  pipeline_tag: image-to-image
9
+ inference: True
10
  tags:
11
  - ControlNet
12
  - super-resolution
app.py DELETED
@@ -1,105 +0,0 @@
1
- import gradio as gr
2
- import numpy as np
3
- import spaces # Ensure this is correctly imported based on Hugging Face's SDK
4
- import torch
5
- from diffusers import FluxControlNetModel, FluxControlNetPipeline
6
- from diffusers.utils import load_image
7
- from gradio_imageslider import ImageSlider
8
- from PIL import Image
9
-
10
- # Initialize global variables for the model and pipeline
11
- controlnet = None
12
- pipe = None
13
-
14
-
15
- @spaces.GPU # Decorator to ensure this function runs on GPU
16
- def initialize_pipeline():
17
- global controlnet, pipe
18
- if controlnet is None or pipe is None:
19
- # Load the ControlNet model with appropriate dtype
20
- controlnet = FluxControlNetModel.from_pretrained(
21
- "jasperai/Flux.1-dev-Controlnet-Upscaler", torch_dtype=torch.float16
22
- )
23
-
24
- # Load the Flux ControlNet Pipeline
25
- pipe = FluxControlNetPipeline.from_pretrained(
26
- "black-forest-labs/FLUX.1-dev",
27
- controlnet=controlnet,
28
- torch_dtype=torch.float16,
29
- )
30
-
31
- # Move the pipeline to GPU
32
- pipe.to("cuda")
33
- return pipe
34
-
35
-
36
- def process_image(input_image):
37
- try:
38
- if input_image is None:
39
- raise gr.Error("Please provide an image to upscale.")
40
-
41
- # Convert the input image (numpy array) to PIL Image
42
- pil_image = Image.fromarray(input_image)
43
-
44
- # Resize the image by a factor of 4 for upscaling
45
- w, h = pil_image.size
46
- control_image = pil_image.resize((w * 4, h * 4))
47
-
48
- # Initialize the pipeline (ensures it's loaded on GPU)
49
- pipe = initialize_pipeline()
50
-
51
- # Perform upscaling using the Flux pipeline
52
- upscaled_image = pipe(
53
- prompt="", # Empty prompt as per your example
54
- control_image=control_image,
55
- controlnet_conditioning_scale=0.6,
56
- num_inference_steps=28,
57
- guidance_scale=3.5,
58
- height=control_image.size[1],
59
- width=control_image.size[0],
60
- ).images[0]
61
-
62
- # Convert the upscaled PIL Image to a numpy array
63
- result_array = np.array(upscaled_image)
64
-
65
- return [input_image, result_array]
66
- except Exception as e:
67
- raise gr.Error(f"An error occurred during processing: {e}")
68
-
69
-
70
- # Define the HTML title and description
71
- title = """<h1 align="center">Flux Upscaler</h1>
72
- <p><center>Upscales your images by 4x using Flux ControlNet Pipeline</center></p>
73
- <p><center>
74
- <a href="https://huggingface.co/jasperai/Flux.1-dev-Controlnet-Upscaler" target="_blank">[ControlNet Model]</a>
75
- <a href="https://huggingface.co/black-forest-labs/FLUX.1-dev" target="_blank">[Flux Pipeline]</a>
76
- </center></p>
77
- <br/>
78
- <p>This application leverages the Flux ControlNet Pipeline for high-quality image upscaling.</p>
79
- """
80
-
81
- # Define the Gradio Blocks interface
82
- with gr.Blocks() as demo:
83
-
84
- gr.HTML(title)
85
-
86
- with gr.Row():
87
- with gr.Column(scale=1):
88
- input_image = gr.Image(label="Input Image", type="numpy")
89
- process_btn = gr.Button(value="Upscale Image", variant="primary")
90
- with gr.Column(scale=1):
91
- output_slider = ImageSlider(label="Before / After", type="numpy")
92
-
93
- process_btn.click(fn=process_image, inputs=[input_image], outputs=output_slider)
94
-
95
- # Add examples (ensure these images are available in your repository)
96
- gr.Examples(
97
- examples=["examples/image1.png", "examples/image2.png"],
98
- inputs=input_image,
99
- outputs=output_slider,
100
- fn=process_image,
101
- cache_examples=True,
102
- )
103
-
104
- # Launch the Gradio app
105
- demo.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
diffusion_pytorch_model.safetensors DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:2a7ea24d2037ff2aa4d25f8b4ce9fe7e739a2cfe6b9d05106788005d5058c8ca
3
- size 3583232168
 
 
 
 
requirements.txt DELETED
@@ -1,5 +0,0 @@
1
- torch>=1.9.0
2
- diffusers>=0.11.1
3
- transformers>=4.15.0
4
- accelerate
5
- Pillow