smdbs commited on
Commit
66d8db1
·
1 Parent(s): a98de27

fix: change test cases and a minor bug

Browse files
Files changed (2) hide show
  1. app.py +4 -4
  2. test.py +16 -71
app.py CHANGED
@@ -3,7 +3,7 @@ from PIL import Image
3
  import gradio as gr
4
  import numpy as np
5
  import os
6
- from typing import Union
7
  import torch
8
  import torch.nn.functional as F
9
  from huggingface_hub import InferenceClient
@@ -45,7 +45,7 @@ def sd_2_1_base(
45
  num_inference_steps: int,
46
  width: int,
47
  height: int,
48
- ) -> Union[np.ndarray, Image.Image, str, Path, None]:
49
  if randomize_seed:
50
  seed = np.random.randint(0, MAX_SEED)
51
  generator = torch.Generator().manual_seed(seed)
@@ -117,7 +117,7 @@ with gr.Blocks() as ui:
117
  label="Width",
118
  minimum=256,
119
  maximum=MAX_IMAGE_SIZE,
120
- step=50,
121
  value=512,
122
  )
123
 
@@ -125,7 +125,7 @@ with gr.Blocks() as ui:
125
  label="Height",
126
  minimum=256,
127
  maximum=MAX_IMAGE_SIZE,
128
- step=50,
129
  value=512,
130
  )
131
 
 
3
  import gradio as gr
4
  import numpy as np
5
  import os
6
+ from typing import Tuple, Union
7
  import torch
8
  import torch.nn.functional as F
9
  from huggingface_hub import InferenceClient
 
45
  num_inference_steps: int,
46
  width: int,
47
  height: int,
48
+ ) -> Tuple[Union[np.ndarray, Image.Image, str, Path, None], int]:
49
  if randomize_seed:
50
  seed = np.random.randint(0, MAX_SEED)
51
  generator = torch.Generator().manual_seed(seed)
 
117
  label="Width",
118
  minimum=256,
119
  maximum=MAX_IMAGE_SIZE,
120
+ step=64,
121
  value=512,
122
  )
123
 
 
125
  label="Height",
126
  minimum=256,
127
  maximum=MAX_IMAGE_SIZE,
128
+ step=64,
129
  value=512,
130
  )
131
 
test.py CHANGED
@@ -1,11 +1,8 @@
1
  import unittest
2
- from huggingface_hub import InferenceClient
3
- from os import path
4
  import os
 
5
 
6
- from app import resnet50
7
- from PIL import Image
8
- import numpy as np
9
 
10
  HF_TOKEN = os.environ.get("HF_TOKEN", "YOUR_HF_TOKEN")
11
  TOKEN_MSG = "Set HF_TOKEN to your Hugging Face token for using InferenceClient"
@@ -16,77 +13,25 @@ class TestGeneralSetup(unittest.TestCase):
16
  def test_setup(self):
17
  self.assertTrue(HF_TOKEN != "YOUR_HF_TOKEN", TOKEN_MSG)
18
 
19
- class TestLocalModelImage(unittest.TestCase):
20
- def test_local_model_image1(self):
21
- p = path.join(path.dirname(__file__), "sample", "pomdog.jpg")
22
- image = Image.open(p)
23
- prediction = resnet50(image, is_local=True)
24
- self.assertTrue(len(prediction))
25
-
26
- def test_local_model_image2(self):
27
- p = path.join(path.dirname(__file__), "sample", "persiancat.jpg")
28
- image = Image.open(p)
29
- prediction = resnet50(image, is_local=True)
30
- self.assertTrue(len(prediction))
31
 
32
- class TestLocalImageArray(unittest.TestCase):
33
  @unittest.skipIf(HF_TOKEN == "YOUR_HF_TOKEN", SKIP_MSG)
34
- def test_array_1(self):
35
- p = path.join(path.dirname(__file__), "sample", "pomdog.jpg")
36
- image = Image.open(p)
37
- image = np.array(image)
38
- prediction = resnet50(image, is_local=False)
39
- self.assertTrue(len(prediction))
40
-
41
-
42
- @unittest.skipIf(HF_TOKEN == "YOUR_HF_TOKEN", SKIP_MSG)
43
- def test_array_2(self):
44
- p = path.join(path.dirname(__file__), "sample", "persiancat.jpg")
45
- image = Image.open(p)
46
- image = np.array(image)
47
- prediction = resnet50(image, is_local=False)
48
- self.assertTrue(len(prediction))
49
-
50
- class TestLocalImagePIL(unittest.TestCase):
51
- @unittest.skipIf(HF_TOKEN == "YOUR_HF_TOKEN", SKIP_MSG)
52
- def test_pil_1(self):
53
- p = path.join(path.dirname(__file__), "sample", "pomdog.jpg")
54
- image = Image.open(p)
55
- prediction = resnet50(image, is_local=False)
56
- self.assertTrue(len(prediction))
57
-
58
- @unittest.skipIf(HF_TOKEN == "YOUR_HF_TOKEN", SKIP_MSG)
59
- def test_pil_2(self):
60
- p = path.join(path.dirname(__file__), "sample", "persiancat.jpg")
61
- image = Image.open(p)
62
- prediction = resnet50(image, is_local=False)
63
- self.assertTrue(len(prediction))
64
 
65
- class TestLocalImageStr(unittest.TestCase):
66
- @unittest.skipIf(HF_TOKEN == "YOUR_HF_TOKEN", SKIP_MSG)
67
- def test_str_1(self):
68
- p = path.join(path.dirname(__file__), "sample", "pomdog.jpg")
69
- prediction = resnet50(p, is_local=False)
70
- self.assertTrue(len(prediction))
71
-
72
- @unittest.skipIf(HF_TOKEN == "YOUR_HF_TOKEN", SKIP_MSG)
73
- def test_str_2(self):
74
- p = path.join(path.dirname(__file__), "sample", "persiancat.jpg")
75
- prediction = resnet50(p, is_local=False)
76
- self.assertTrue(len(prediction))
77
 
78
- class TestRemoteImageUrl(unittest.TestCase):
79
  @unittest.skipIf(HF_TOKEN == "YOUR_HF_TOKEN", SKIP_MSG)
80
  def test_url_1(self):
81
- url = "https://i.ytimg.com/vi/AQSTQ4VUPH4/maxresdefault.jpg"
82
- prediction = resnet50(url, is_local=False)
83
- self.assertTrue(len(prediction))
84
-
85
- @unittest.skipIf(HF_TOKEN == "YOUR_HF_TOKEN", SKIP_MSG)
86
- def test_url_2(self):
87
- url = "https://img.thrfun.com/img/200/610/breed_information_persian_x1.jpg"
88
- prediction = resnet50(url, is_local=False)
89
- self.assertTrue(len(prediction))
90
-
91
  if __name__ == "__main__":
92
  unittest.main()
 
1
  import unittest
 
 
2
  import os
3
+ import torch
4
 
5
+ from app import sd_2_1_base
 
 
6
 
7
  HF_TOKEN = os.environ.get("HF_TOKEN", "YOUR_HF_TOKEN")
8
  TOKEN_MSG = "Set HF_TOKEN to your Hugging Face token for using InferenceClient"
 
13
  def test_setup(self):
14
  self.assertTrue(HF_TOKEN != "YOUR_HF_TOKEN", TOKEN_MSG)
15
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ class TestLocalModel(unittest.TestCase):
18
  @unittest.skipIf(HF_TOKEN == "YOUR_HF_TOKEN", SKIP_MSG)
19
+ @unittest.skipIf(not torch.cuda.is_available(), "CUDA is not available")
20
+ def test_url_1(self):
21
+ image, _ = sd_2_1_base(
22
+ "A photo of a cat", True, "A photo of a dog", 42, False, 0.1, 10, 128, 128
23
+ )
24
+ self.assertIsNotNone(image)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ class TestAPIModel(unittest.TestCase):
28
  @unittest.skipIf(HF_TOKEN == "YOUR_HF_TOKEN", SKIP_MSG)
29
  def test_url_1(self):
30
+ image, _ = sd_2_1_base(
31
+ "A photo of a cat", False, "A photo of a dog", 42, False, 0.1, 10, 128, 128
32
+ )
33
+ self.assertIsNotNone(image)
34
+
35
+
 
 
 
 
36
  if __name__ == "__main__":
37
  unittest.main()