lim123 commited on
Commit
7afc912
β€’
1 Parent(s): 15d1b1d

Upload 6 files

Browse files
Files changed (6) hide show
  1. README.md +5 -7
  2. app.py +57 -0
  3. gitattributes.txt +27 -0
  4. n02381460_360.jpg +0 -0
  5. n02381460_4410.jpg +0 -0
  6. requirements.txt +1 -0
README.md CHANGED
@@ -1,13 +1,11 @@
1
  ---
2
- title: Cyclegan Test
3
- emoji: πŸ‘
4
- colorFrom: indigo
5
- colorTo: blue
6
  sdk: gradio
7
- sdk_version: 3.8
8
  app_file: app.py
9
  pinned: false
10
- license: apache-2.0
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: CycleGAN
3
+ emoji: πŸŽπŸ¦“
4
+ colorFrom: blue
5
+ colorTo: red
6
  sdk: gradio
 
7
  app_file: app.py
8
  pinned: false
 
9
  ---
10
 
11
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ import numpy as np
3
+
4
+ import tensorflow as tf
5
+
6
+ import gradio as gr
7
+
8
+ from huggingface_hub import from_pretrained_keras
9
+
10
+ model = from_pretrained_keras("keras-io/CycleGAN", compile=False)
11
+
12
+ # Define the standard image size.
13
+ orig_img_size = (286, 286)
14
+ # Size of the random crops to be used during training.
15
+ input_img_size = (256, 256, 3)
16
+
17
+
18
+ def normalize_img(img):
19
+ img = tf.cast(img, dtype=tf.float32)
20
+ # Map values in the range [-1, 1]
21
+ return (img / 127.5) - 1.0
22
+
23
+
24
+ def preprocess_test_image(img):
25
+ # Only resizing and normalization for the test images.
26
+ img = tf.image.resize(img, [input_img_size[0], input_img_size[1]])
27
+ img = normalize_img(img)
28
+ return img
29
+
30
+
31
+ # img_path = './n02381460_1010.jpg'
32
+
33
+
34
+ def generate_img(img_path):
35
+ img = tf.io.read_file(img_path)
36
+ img = tf.image.decode_png(img)
37
+ img = tf.expand_dims(img, axis=0)
38
+ img = preprocess_test_image(img)
39
+ prediction = model(img, training=False)[0].numpy()
40
+ prediction = (prediction * 127.5 + 127.5).astype(np.uint8)
41
+ return prediction
42
+
43
+
44
+ image = gr.inputs.Image(type="filepath")
45
+ op = gr.outputs.Image(type="numpy")
46
+
47
+ iface = gr.Interface(
48
+ generate_img,
49
+ image,
50
+ op,
51
+ title="CycleGAN",
52
+ description='Keras Implementation of CycleGAN model using Horse to Zebra dataset',
53
+ article='Author: <a href="https://huggingface.co/anuragshas">Anurag Singh</a>. Based on the keras example from <a href="https://keras.io/examples/generative/cyclegan/">A_K_Nain</a>',
54
+ examples=["n02381460_360.jpg", "n02381460_4410.jpg"],
55
+ )
56
+
57
+ iface.launch(cache_examples=True)
gitattributes.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.onnx filter=lfs diff=lfs merge=lfs -text
14
+ *.ot filter=lfs diff=lfs merge=lfs -text
15
+ *.parquet filter=lfs diff=lfs merge=lfs -text
16
+ *.pb filter=lfs diff=lfs merge=lfs -text
17
+ *.pt filter=lfs diff=lfs merge=lfs -text
18
+ *.pth filter=lfs diff=lfs merge=lfs -text
19
+ *.rar filter=lfs diff=lfs merge=lfs -text
20
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
22
+ *.tflite filter=lfs diff=lfs merge=lfs -text
23
+ *.tgz filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
n02381460_360.jpg ADDED
n02381460_4410.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ tensorflow>2.6