b3h-young123 commited on
Commit
514504e
·
verified ·
1 Parent(s): 8551d56

Add files using upload-large-folder tool

Browse files
Ilaria_Upscaler/.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ ilariaaisuite.png filter=lfs diff=lfs merge=lfs -text
Ilaria_Upscaler/LICENSE.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Ilaria's Non-Commercial Use License (INCU)
2
+
3
+ ## 1. Definitions
4
+
5
+ - "Software" refers to the content present within this repository including code, graphics, sounds, images, text, and other files.
6
+ - "You" refers to the individual or entity that wishes to use the Software.
7
+ - "Ilaria" refers to the original creator of the Software.
8
+ - "Fork" refers to the action of creating a personal copy of another user's repository.
9
+
10
+ ## 2. Grant of Rights
11
+
12
+ Subject to the terms of this license, Ilaria hereby grants You a worldwide, royalty-free, non-exclusive, perpetual license to use the Software for personal, non-commercial purposes. This includes the rights to use, copy, modify, merge, publish, and distribute the Software for non-commercial purposes.
13
+
14
+ ## 3. Redistribution
15
+
16
+ You may not distribute or sell the Software, or any derivative works based on the Software, unless you have been specifically granted permission by Ilaria. Any permitted redistribution must also be under the terms of this license. Unauthorized distribution is strictly prohibited and will result in the termination of this license.
17
+
18
+ ## 4. Commercial Use
19
+
20
+ Commercial use of the Software is strictly prohibited without the express written consent of Ilaria. Small businesses may be granted permission to use the Software for profit, but large corporations must negotiate a commercial agreement with Ilaria. Unauthorized commercial use is strictly prohibited and will result in the termination of this license.
21
+
22
+ ## 5. Forking and Personal Use
23
+
24
+ You are free to fork and modify the Software for your own personal use. You may not distribute, publicly display, or create derivative works from your modifications unless granted permission by Ilaria. All modifications must also be under the terms of this license.
25
+
26
+ ## 6. Liability
27
+
28
+ Ilaria provides the Software "as is," without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall Ilaria be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the Software or the use or other dealings in the Software. You agree to use the Software at your own risk.
29
+
30
+ ## 7. Governing Law
31
+
32
+ This license is governed by the laws of the jurisdiction in which Ilaria resides. Any disputes related to this license will be resolved in the courts of that jurisdiction.
Ilaria_Upscaler/README.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Ilaria Upscaler
3
+ emoji: 🌖
4
+ colorFrom: pink
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 4.36.1
8
+ app_file: app.py
9
+ pinned: true
10
+ ---
11
+
12
+ ![Ilaria AI Suite](./ilariaaisuite.png)
13
+ ***
14
+ [![Static Badge](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Space-s?labelColor=YELLOW&color=FFEA00)](https://huggingface.co/spaces/TheStinger/Ilaria_Upscaler) [![Static Badge](https://img.shields.io/badge/%F0%9F%A4%97%20HF%20Space-Duplication-s?labelColor=YELLOW&color=FFEA00)](https://huggingface.co/spaces/TheStinger/Ilaria_Upscaler?duplicate=true) [![Static Badge](https://img.shields.io/badge/GitHub-Source%20Code-s?logo=GitHub)](https://github.com/TheStingerX/Ilaria-Upscaler) [![Static Badge](https://img.shields.io/badge/AI%20Hub-Discord%20Server-s?logo=Discord&color=%09%237289da)](https://discord.gg/aihub) [![Static Badge](https://img.shields.io/badge/Ko--Fi-s?logo=Ko-Fi&label=Support%20me%20on&labelColor=434b57&color=FF5E5B)](https://ko-fi.com/ilariaowo)
15
+ ***
16
+ <p align="center">
17
+ <h1>Ilaria Upscaler 💖</h1>
18
+ </p>
19
+
20
+ 🎉 Welcome to Ilaria Upscaler! 🎉
21
+
22
+ This project leverages various libraries and modules to create a Graphical User Interface (GUI) for upscaling images.
23
+ It's primarily designed for use with HuggingFace Spaces. 🤗
24
+
25
+ Ilaria Upscaler is part of the Ilaria AI Suite wich includes various easy and powerful tools. 💖
26
+
27
+ ## 📦 Installation 📦
28
+
29
+ To use this project, clone the original Space on Hugging Face.
30
+ Make sure you restart it time to time to keep up with the new updates.
31
+
32
+ ## 🖥️ Usage 🖥️
33
+
34
+ Once the dependencies are installed automatically, Hugging Face will use app.py to start the user interface.
35
+ From there, you can utilize the various features of the project.
36
+
37
+ ## 🌟 Features 🌟
38
+
39
+ Ilaria Upscaler offers a range of features, including:
40
+
41
+ - 🖼️ **Image Upscaling and Restoration**:
42
+ Ilaria Upscaler uses the RealESRGANer class from the realesrgan module to upscale and restore images.
43
+ It supports multiple models, each with different scales and architectures, providing flexibility in the upscaling process.
44
+
45
+ - 🎛️ **Adjustable Parameters**:
46
+ The realesrgan function allows users to adjust various parameters such as the model name, denoise strength, face enhancement, and output scale.
47
+ This provides a high level of customization to fit different use cases.
48
+
49
+ - 🖥️ **User-Friendly Web Interface**:
50
+ Ilaria Upscaler The code uses the gradio module to create an intuitive web interface.
51
+ Users can easily upload an image, and the application will return the upscaled and restored image.
52
+
53
+ - 📂 **Efficient File Handling**:
54
+ The code uses the os and basicsr.utils.download_util modules for efficient file handling operations.
55
+ It checks if the model file exists in the local directory, and if not, it downloads the file from the specified URL.
56
+
57
+ - 👩 **Face Enhancement Option**:
58
+ If the face_enhance parameter is set to True, the code uses the GFPGANer class from the gfpgan module to enhance faces in the image.
59
+ This is particularly useful for images with faces that need to be upscaled and enhanced separately from the rest of the image.
60
+
61
+ ## 🙏 Credits 🙏
62
+
63
+ - **Squishy** - For helping me with the ideas
64
+
65
+ ## 🤝 Contributing 🤝
66
+
67
+ Interested in contributing to this project? Ilaria is always looking for collaborators.
68
+ Feel free to open a pull request on Hugging Face.
69
+
70
+ ## 📄 License 📄
71
+
72
+ This project is released under the `INCU` license.
73
+ For more details, please check the license file.
74
+ For further questions feel free to contact Ilaria.
Ilaria_Upscaler/app.py ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy
4
+ import os
5
+ import random
6
+ from basicsr.archs.rrdbnet_arch import RRDBNet
7
+ from basicsr.utils.download_util import load_file_from_url
8
+ from realesrgan import RealESRGANer
9
+ from realesrgan.archs.srvgg_arch import SRVGGNetCompact
10
+ from torchvision.transforms.functional import rgb_to_grayscale
11
+ import spaces
12
+
13
+ last_file = None
14
+ img_mode = "RGBA"
15
+
16
+ @spaces.GPU
17
+ def realesrgan(img, model_name, denoise_strength, face_enhance, outscale):
18
+ """Real-ESRGAN function to restore (and upscale) images."""
19
+ if not img:
20
+ return
21
+
22
+ # Define model parameters
23
+ if model_name == 'RealESRGAN_x4plus':
24
+ model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
25
+ netscale = 4
26
+ file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth']
27
+ elif model_name == 'RealESRNet_x4plus':
28
+ model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
29
+ netscale = 4
30
+ file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth']
31
+ elif model_name == 'RealESRGAN_x4plus_anime_6B':
32
+ model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=6, num_grow_ch=32, scale=4)
33
+ netscale = 4
34
+ file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth']
35
+ elif model_name == 'RealESRGAN_x2plus':
36
+ model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
37
+ netscale = 2
38
+ file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth']
39
+ elif model_name == 'realesr-general-x4v3':
40
+ model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
41
+ netscale = 4
42
+ file_url = [
43
+ 'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth',
44
+ 'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth'
45
+ ]
46
+
47
+ model_path = os.path.join('weights', model_name + '.pth')
48
+ if not os.path.isfile(model_path):
49
+ ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
50
+ for url in file_url:
51
+ model_path = load_file_from_url(
52
+ url=url, model_dir=os.path.join(ROOT_DIR, 'weights'), progress=True, file_name=None)
53
+
54
+ dni_weight = None
55
+ if model_name == 'realesr-general-x4v3' and denoise_strength != 1:
56
+ wdn_model_path = model_path.replace('realesr-general-x4v3', 'realesr-general-wdn-x4v3')
57
+ model_path = [model_path, wdn_model_path]
58
+ dni_weight = [denoise_strength, 1 - denoise_strength]
59
+
60
+ upsampler = RealESRGANer(
61
+ scale=netscale,
62
+ model_path=model_path,
63
+ dni_weight=dni_weight,
64
+ model=model,
65
+ tile=0,
66
+ tile_pad=10,
67
+ pre_pad=10,
68
+ half=False,
69
+ gpu_id=None
70
+ )
71
+
72
+ if face_enhance:
73
+ from gfpgan import GFPGANer
74
+ face_enhancer = GFPGANer(
75
+ model_path='https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth',
76
+ upscale=outscale,
77
+ arch='clean',
78
+ channel_multiplier=2,
79
+ bg_upsampler=upsampler)
80
+
81
+ cv_img = numpy.array(img)
82
+ img = cv2.cvtColor(cv_img, cv2.COLOR_RGBA2BGRA)
83
+
84
+ try:
85
+ if face_enhance:
86
+ _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
87
+ else:
88
+ output, _ = upsampler.enhance(img, outscale=outscale)
89
+ except RuntimeError as error:
90
+ print('Error', error)
91
+ print('If you encounter CUDA out of memory, try to set --tile with a smaller number.')
92
+ else:
93
+ extension = 'png' if img_mode == 'RGBA' else 'jpg'
94
+
95
+ out_filename = f"output_{rnd_string(8)}.{extension}"
96
+ cv2.imwrite(out_filename, output)
97
+ global last_file
98
+ last_file = out_filename
99
+
100
+ output_img = cv2.cvtColor(output, cv2.COLOR_BGRA2RGBA) if img_mode == "RGBA" else output
101
+ return out_filename, image_properties(output_img)
102
+
103
+ def rnd_string(x):
104
+ characters = "abcdefghijklmnopqrstuvwxyz_0123456789"
105
+ return "".join((random.choice(characters)) for i in range(x))
106
+
107
+ def reset():
108
+ global last_file
109
+ if last_file:
110
+ print(f"Deleting {last_file} ...")
111
+ os.remove(last_file)
112
+ last_file = None
113
+ return gr.update(value=None), gr.update(value=None), gr.update(value=None)
114
+
115
+ def has_transparency(img):
116
+ if img.info.get("transparency", None) is not None:
117
+ return True
118
+ if img.mode == "P":
119
+ transparent = img.info.get("transparency", -1)
120
+ for _, index in img.getcolors():
121
+ if index == transparent:
122
+ return True
123
+ elif img.mode == "RGBA":
124
+ extrema = img.getextrema()
125
+ if extrema[3][0] < 255:
126
+ return True
127
+ return False
128
+
129
+ def image_properties(img):
130
+ """Returns the dimensions (width and height) and color mode of the input image and
131
+ also sets the global img_mode variable to be used by the realesrgan function
132
+ """
133
+ global img_mode
134
+ if img is None: # Explicitly check for None
135
+ return "No image data available."
136
+
137
+ if isinstance(img, numpy.ndarray): # Handle NumPy array case
138
+ height, width = img.shape[:2]
139
+ channels = img.shape[2] if len(img.shape) > 2 else 1
140
+ img_mode = "RGBA" if channels == 4 else "RGB" if channels == 3 else "Grayscale"
141
+ return f"Resolution: Width: {width}, Height: {height} | Color Mode: {img_mode}"
142
+
143
+ if hasattr(img, "info") and hasattr(img, "mode") and hasattr(img, "size"): # Handle PIL images
144
+ if has_transparency(img):
145
+ img_mode = "RGBA"
146
+ else:
147
+ img_mode = "RGB"
148
+ return f"Resolution: Width: {img.size[0]}, Height: {img.size[1]} | Color Mode: {img_mode}"
149
+
150
+ return "Unsupported image format."
151
+
152
+ def main():
153
+ with gr.Blocks(theme=gr.themes.Default(primary_hue="pink", secondary_hue="rose"), title="Ilaria Upscaler 💖") as app:
154
+
155
+ gr.Markdown(
156
+ """# <div align="center"> Ilaria Upscaler 💖 </div>
157
+ """
158
+ )
159
+ with gr.Accordion("Upscaling option"):
160
+ with gr.Row():
161
+ model_name = gr.Dropdown(label="Model",
162
+ choices=["RealESRGAN_x4plus", "RealESRNet_x4plus", "RealESRGAN_x4plus_anime_6B", "RealESRGAN_x2plus", "realesr-general-x4v3"],
163
+ value="RealESRGAN_x4plus")
164
+ denoise_strength = gr.Slider(label="Denoise Strength", minimum=0, maximum=1, step=0.1, value=0.5)
165
+ outscale = gr.Slider(label="Resolution Upscale", minimum=1, maximum=6, step=1, value=4)
166
+ face_enhance = gr.Checkbox(label="Face Enhancement")
167
+
168
+ with gr.Row():
169
+ with gr.Group():
170
+ input_image = gr.Image(label="Input Image", type="pil")
171
+ input_properties = gr.Textbox(label="Input Image Properties", interactive=False)
172
+
173
+ with gr.Group():
174
+ output_image = gr.Image(label="Output Image")
175
+ output_properties = gr.Textbox(label="Output Image Properties", interactive=False)
176
+
177
+ with gr.Row():
178
+ reset_btn = gr.Button("Reset")
179
+ upscale_btn = gr.Button("Upscale")
180
+
181
+ input_image.change(fn=image_properties, inputs=input_image, outputs=input_properties)
182
+ upscale_btn.click(fn=realesrgan,
183
+ inputs=[input_image, model_name, denoise_strength, face_enhance, outscale],
184
+ outputs=[output_image, output_properties])
185
+ reset_btn.click(fn=reset, inputs=[], outputs=[input_image, output_image, input_properties])
186
+
187
+ gr.Markdown(
188
+ """Made with love by Ilaria 💖 | Support me on [Ko-Fi](https://ko-fi.com/ilariaowo) | Using [Real-ESRGAN](https://github.com/xinntao/Real-ESRGAN).
189
+ """
190
+ )
191
+
192
+ app.launch()
193
+
194
+ if __name__ == "__main__":
195
+ main()
Ilaria_Upscaler/ilariaaisuite.png ADDED

Git LFS Details

  • SHA256: 60831754632678b333f6301cddb6c96234cfec9750424e60dbed657e0541fcfc
  • Pointer size: 132 Bytes
  • Size of remote file: 2.76 MB
Ilaria_Upscaler/requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ torchvision
3
+ numpy
4
+ opencv-python
5
+ Pillow
6
+ basicsr @ git+https://github.com/XPixelGroup/BasicSR.git
7
+ facexlib
8
+ gfpgan
9
+ tqdm
10
+ gradio
11
+ realesrgan