Spaces:
Runtime error
Runtime error
TuringsSolutions
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ from keras.models import Model
|
|
6 |
import matplotlib.pyplot as plt
|
7 |
import logging
|
8 |
from skimage.transform import resize
|
9 |
-
from PIL import Image, ImageEnhance
|
10 |
from tqdm import tqdm
|
11 |
|
12 |
class SwarmAgent:
|
@@ -19,7 +19,7 @@ class SwarmAgent:
|
|
19 |
class SwarmNeuralNetwork:
|
20 |
def __init__(self, num_agents, image_shape, target_image):
|
21 |
self.image_shape = image_shape
|
22 |
-
self.resized_shape = (
|
23 |
self.agents = [SwarmAgent(self.random_position(), self.random_velocity()) for _ in range(num_agents)]
|
24 |
self.target_image = self.load_target_image(target_image)
|
25 |
self.generated_image = np.random.randn(*image_shape) # Start with noise
|
@@ -105,8 +105,9 @@ class SwarmNeuralNetwork:
|
|
105 |
|
106 |
# Apply sharpening filter
|
107 |
image_pil = Image.fromarray((self.generated_image * 255).astype(np.uint8))
|
108 |
-
|
109 |
-
|
|
|
110 |
|
111 |
def train(self, epochs):
|
112 |
logging.basicConfig(filename='training.log', level=logging.INFO)
|
@@ -163,7 +164,7 @@ class SwarmNeuralNetwork:
|
|
163 |
|
164 |
# Gradio Interface
|
165 |
def train_snn(image, num_agents, epochs, brightness, contrast, color):
|
166 |
-
snn = SwarmNeuralNetwork(num_agents=num_agents, image_shape=(
|
167 |
|
168 |
# Apply user-specified adjustments to the target image
|
169 |
image = ImageEnhance.Brightness(image).enhance(brightness)
|
@@ -176,7 +177,7 @@ def train_snn(image, num_agents, epochs, brightness, contrast, color):
|
|
176 |
return snn.generated_image
|
177 |
|
178 |
def generate_new_image():
|
179 |
-
snn = SwarmNeuralNetwork(num_agents=2000, image_shape=(
|
180 |
snn.load_model('snn_model.npy')
|
181 |
new_image = snn.generate_new_image()
|
182 |
return new_image
|
|
|
6 |
import matplotlib.pyplot as plt
|
7 |
import logging
|
8 |
from skimage.transform import resize
|
9 |
+
from PIL import Image, ImageEnhance, ImageFilter
|
10 |
from tqdm import tqdm
|
11 |
|
12 |
class SwarmAgent:
|
|
|
19 |
class SwarmNeuralNetwork:
|
20 |
def __init__(self, num_agents, image_shape, target_image):
|
21 |
self.image_shape = image_shape
|
22 |
+
self.resized_shape = (128, 128, 3) # Increased resolution
|
23 |
self.agents = [SwarmAgent(self.random_position(), self.random_velocity()) for _ in range(num_agents)]
|
24 |
self.target_image = self.load_target_image(target_image)
|
25 |
self.generated_image = np.random.randn(*image_shape) # Start with noise
|
|
|
105 |
|
106 |
# Apply sharpening filter
|
107 |
image_pil = Image.fromarray((self.generated_image * 255).astype(np.uint8))
|
108 |
+
image_pil = image_pil.filter(ImageFilter.SHARPEN)
|
109 |
+
image_pil = image_pil.filter(ImageFilter.DETAIL)
|
110 |
+
self.generated_image = np.array(image_pil) / 255.0
|
111 |
|
112 |
def train(self, epochs):
|
113 |
logging.basicConfig(filename='training.log', level=logging.INFO)
|
|
|
164 |
|
165 |
# Gradio Interface
|
166 |
def train_snn(image, num_agents, epochs, brightness, contrast, color):
|
167 |
+
snn = SwarmNeuralNetwork(num_agents=num_agents, image_shape=(128, 128, 3), target_image=image)
|
168 |
|
169 |
# Apply user-specified adjustments to the target image
|
170 |
image = ImageEnhance.Brightness(image).enhance(brightness)
|
|
|
177 |
return snn.generated_image
|
178 |
|
179 |
def generate_new_image():
|
180 |
+
snn = SwarmNeuralNetwork(num_agents=2000, image_shape=(128, 128, 3), target_image=None)
|
181 |
snn.load_model('snn_model.npy')
|
182 |
new_image = snn.generate_new_image()
|
183 |
return new_image
|