manupawar6388 commited on
Commit
1487cf9
·
1 Parent(s): 6e99dc5

Add Gradio app for DCGAN chess piece generator

Browse files
Files changed (3) hide show
  1. README.md +16 -5
  2. app.py +68 -0
  3. requirements.txt +5 -0
README.md CHANGED
@@ -1,13 +1,24 @@
1
  ---
2
- title: Chessman Image-DCGAN
3
- emoji: 🐠
4
- colorFrom: purple
5
- colorTo: gray
6
  sdk: gradio
7
  sdk_version: 6.5.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
 
 
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
1
  ---
2
+ title: Chessman DCGAN Generator
3
+ emoji: ♟️
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: gradio
7
  sdk_version: 6.5.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
+ tags:
12
+ - gan
13
+ - dcgan
14
+ - image-generation
15
+ - chess
16
  ---
17
 
18
+ # ♟️ Chessman DCGAN Generator
19
+
20
+ Generate unique AI-created chess piece images using a Deep Convolutional GAN!
21
+
22
+ This Space uses a DCGAN model trained on the Chessman Image Dataset to generate 64×64 RGB images of chess pieces.
23
+
24
+ **Model**: [manupawar6388/Chessman_image-DCGAN](https://huggingface.co/manupawar6388/Chessman_image-DCGAN)
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+ from huggingface_hub import hf_hub_download
6
+
7
+ # Download and load the model
8
+ model_path = hf_hub_download(
9
+ repo_id="manupawar6388/Chessman_image-DCGAN",
10
+ filename="dcgan_generator.keras"
11
+ )
12
+ generator = tf.keras.models.load_model(model_path)
13
+
14
+ def generate_chess_piece():
15
+ """Generate a random chess piece image"""
16
+ # Generate random noise
17
+ noise = tf.random.normal([1, 100])
18
+
19
+ # Generate image
20
+ generated_image = generator(noise, training=False)
21
+
22
+ # Rescale to [0, 255]
23
+ img_array = ((generated_image[0, :, :, :] * 127.5) + 127.5).numpy().astype("uint8")
24
+
25
+ # Convert to PIL Image
26
+ img = Image.fromarray(img_array)
27
+
28
+ return img
29
+
30
+ # Create Gradio interface
31
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
32
+ gr.Markdown(
33
+ """
34
+ # ♟️ Chessman DCGAN Generator
35
+
36
+ Generate unique AI-created chess piece images using a Deep Convolutional GAN trained on the Chessman Image Dataset.
37
+
38
+ **Model**: DCGAN (50 epochs) | **Output**: 64×64 RGB images
39
+ """
40
+ )
41
+
42
+ with gr.Row():
43
+ with gr.Column():
44
+ generate_btn = gr.Button("🎲 Generate Chess Piece", variant="primary", size="lg")
45
+
46
+ with gr.Column():
47
+ output_image = gr.Image(label="Generated Chess Piece", type="pil")
48
+
49
+ gr.Markdown(
50
+ """
51
+ ### About
52
+ This model uses a Deep Convolutional Generative Adversarial Network (DCGAN) to generate chess piece images.
53
+ Each generation is unique, created from random noise.
54
+
55
+ **Dataset**: [Chessman Image Dataset](https://www.kaggle.com/datasets/niteshfre/chessman-image-dataset) (552 images)
56
+
57
+ **Model Repository**: [manupawar6388/Chessman_image-DCGAN](https://huggingface.co/manupawar6388/Chessman_image-DCGAN)
58
+ """
59
+ )
60
+
61
+ # Event handler
62
+ generate_btn.click(fn=generate_chess_piece, outputs=output_image)
63
+
64
+ # Generate on load
65
+ demo.load(fn=generate_chess_piece, outputs=output_image)
66
+
67
+ if __name__ == "__main__":
68
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ tensorflow>=2.10.0
2
+ gradio>=4.0.0
3
+ huggingface-hub>=0.20.0
4
+ pillow>=9.0.0
5
+ numpy>=1.23.0