File size: 1,733 Bytes
5af0d63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bf38ef4
522b237
bf38ef4
5af0d63
bf38ef4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
826eff3
bf38ef4
5af0d63
 
2cff570
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import tensorflow as tf
from tensorflow.keras.models import load_model
import numpy as np
from PIL import Image
import gradio as gr

# Load the saved generator model
generator = load_model('DCGEN_50_epochs.h5')

latent_dim = 300  # Assuming the model expects a latent dimension of 300

# Function to generate images using the generator model
def generate_images(generator, num_images, latent_dim):
    noise = tf.random.normal([num_images, latent_dim])
    generated_images = generator.predict(noise)
    generated_images = (generated_images * 127.5) + 127.5  # Denormalize
    return generated_images

# Function to convert generated images to a list of PIL Images
def generate_pil_images():
    generated_images = generate_images(generator, 16, latent_dim)
    pil_images = [Image.fromarray(np.uint8(image)) for image in generated_images]
    return pil_images

# Path to the video of training images visualization
training_video_path = "anime-gan-training.mp4"  # Replace with your video file path

# Create a Gradio interface
with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            gr.Markdown("# Generated Images")
            gr.Interface(
                fn=generate_pil_images,
                inputs=[],
                outputs=gr.Gallery(label="Generated Images", columns=4, height="fill"),
                live=True  # Live interface so it updates every time you refresh
            )
        with gr.Column():
            gr.Markdown("# Training Visualization Video")
            gr.Video(
                value=training_video_path,
                label="Training Visualization",
                format="mp4",
                autoplay=True
            )

# Launch the Gradio app
demo.launch()