Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import numpy as np
|
|
8 |
from PIL import Image, ImageEnhance
|
9 |
from deep_translator import GoogleTranslator
|
10 |
import json
|
|
|
11 |
|
12 |
# Project by Nymbo
|
13 |
alto_api= "https://api-inference.huggingface.co/models/enhanceaiteam/Flux-uncensored"
|
@@ -90,7 +91,7 @@ def compress_image(image, quality=50):
|
|
90 |
compressed_image = Image.open(buffer)
|
91 |
return compressed_image
|
92 |
|
93 |
-
def query(prompt):
|
94 |
if prompt == "" or prompt == None:
|
95 |
return None
|
96 |
|
@@ -100,7 +101,8 @@ def query(prompt):
|
|
100 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
101 |
|
102 |
payload = {
|
103 |
-
"inputs": prompt
|
|
|
104 |
}
|
105 |
|
106 |
response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
|
@@ -115,20 +117,21 @@ def query(prompt):
|
|
115 |
image_bytes = response.content
|
116 |
image = Image.open(io.BytesIO(image_bytes))
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
132 |
|
133 |
print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
|
134 |
return image
|
@@ -161,12 +164,13 @@ with gr.Blocks(theme='gstaff/xkcd', css=css) as app:
|
|
161 |
with gr.Column(elem_id="prompt-container"):
|
162 |
with gr.Row():
|
163 |
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input", value=test_prompt)
|
|
|
164 |
|
165 |
with gr.Row():
|
166 |
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
167 |
with gr.Row():
|
168 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
169 |
|
170 |
-
text_button.click(query, inputs=[text_prompt], outputs=image_output)
|
171 |
|
172 |
app.launch(show_api=True, share=True)
|
|
|
8 |
from PIL import Image, ImageEnhance
|
9 |
from deep_translator import GoogleTranslator
|
10 |
import json
|
11 |
+
import randint from random
|
12 |
|
13 |
# Project by Nymbo
|
14 |
alto_api= "https://api-inference.huggingface.co/models/enhanceaiteam/Flux-uncensored"
|
|
|
91 |
compressed_image = Image.open(buffer)
|
92 |
return compressed_image
|
93 |
|
94 |
+
def query(prompt, is_realistic):
|
95 |
if prompt == "" or prompt == None:
|
96 |
return None
|
97 |
|
|
|
101 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
102 |
|
103 |
payload = {
|
104 |
+
"inputs": prompt,
|
105 |
+
"seed": random.randint(1, 1000000000)
|
106 |
}
|
107 |
|
108 |
response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
|
|
|
117 |
image_bytes = response.content
|
118 |
image = Image.open(io.BytesIO(image_bytes))
|
119 |
|
120 |
+
if (is_realstic == True):
|
121 |
+
image = add_noise(image, intensity = randint(75, 125) / 10)
|
122 |
+
image = resize_and_crop(image, 360, 640)
|
123 |
+
image = compress_image(image, randint(75, 95))
|
124 |
+
|
125 |
+
# Изменение насыщенности
|
126 |
+
enhancer = ImageEnhance.Color(image)
|
127 |
+
image = enhancer.enhance(randint(70,90) / 100)
|
128 |
+
|
129 |
+
# Изменение экспозиции (яркости)
|
130 |
+
enhancer = ImageEnhance.Brightness(image)
|
131 |
+
image = enhancer.enhance(randint(100,110) / 100)
|
132 |
+
|
133 |
+
enhancer = ImageEnhance.Contrast(image)
|
134 |
+
image = enhancer.enhance(randint(80,95) / 100)
|
135 |
|
136 |
print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
|
137 |
return image
|
|
|
164 |
with gr.Column(elem_id="prompt-container"):
|
165 |
with gr.Row():
|
166 |
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input", value=test_prompt)
|
167 |
+
is_realistic = gr.Checkbox(label="Home-made filter", value=True)
|
168 |
|
169 |
with gr.Row():
|
170 |
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
171 |
with gr.Row():
|
172 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
173 |
|
174 |
+
text_button.click(query, inputs=[text_prompt, is_realistic], outputs=image_output)
|
175 |
|
176 |
app.launch(show_api=True, share=True)
|