TuringsSolutions
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
import tensorflow as tf
|
@@ -86,6 +87,7 @@ class SwarmNeuralNetwork:
|
|
86 |
|
87 |
return np.array(losses)
|
88 |
|
|
|
89 |
def update_agents(self, timestep):
|
90 |
noise_level = self.noise_schedule[min(timestep, len(self.noise_schedule) - 1)]
|
91 |
|
@@ -102,6 +104,7 @@ class SwarmNeuralNetwork:
|
|
102 |
# Clip values
|
103 |
agent.position = np.clip(agent.position, -1, 1)
|
104 |
|
|
|
105 |
def generate_image(self):
|
106 |
self.generated_image = np.mean([agent.position for agent in self.agents], axis=0)
|
107 |
# Normalize to [0, 1] range for display
|
@@ -113,6 +116,7 @@ class SwarmNeuralNetwork:
|
|
113 |
image_pil = image_pil.filter(ImageFilter.SHARPEN)
|
114 |
self.generated_image = np.array(image_pil) / 255.0
|
115 |
|
|
|
116 |
def train(self, epochs):
|
117 |
logging.basicConfig(filename='training.log', level=logging.INFO)
|
118 |
|
@@ -156,6 +160,7 @@ class SwarmNeuralNetwork:
|
|
156 |
self.generated_image = model_state['generated_image']
|
157 |
self.current_epoch = model_state['current_epoch']
|
158 |
|
|
|
159 |
def generate_new_image(self, num_steps=500): # Optimized number of steps
|
160 |
for agent in self.agents:
|
161 |
agent.position = np.random.randn(*self.image_shape)
|
|
|
1 |
import os
|
2 |
+
import spaces
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
import tensorflow as tf
|
|
|
87 |
|
88 |
return np.array(losses)
|
89 |
|
90 |
+
@spaces.GPU(duration=120)
|
91 |
def update_agents(self, timestep):
|
92 |
noise_level = self.noise_schedule[min(timestep, len(self.noise_schedule) - 1)]
|
93 |
|
|
|
104 |
# Clip values
|
105 |
agent.position = np.clip(agent.position, -1, 1)
|
106 |
|
107 |
+
@spaces.GPU(duration=120)
|
108 |
def generate_image(self):
|
109 |
self.generated_image = np.mean([agent.position for agent in self.agents], axis=0)
|
110 |
# Normalize to [0, 1] range for display
|
|
|
116 |
image_pil = image_pil.filter(ImageFilter.SHARPEN)
|
117 |
self.generated_image = np.array(image_pil) / 255.0
|
118 |
|
119 |
+
@spaces.GPU(duration=120)
|
120 |
def train(self, epochs):
|
121 |
logging.basicConfig(filename='training.log', level=logging.INFO)
|
122 |
|
|
|
160 |
self.generated_image = model_state['generated_image']
|
161 |
self.current_epoch = model_state['current_epoch']
|
162 |
|
163 |
+
@spaces.GPU(duration=120)
|
164 |
def generate_new_image(self, num_steps=500): # Optimized number of steps
|
165 |
for agent in self.agents:
|
166 |
agent.position = np.random.randn(*self.image_shape)
|