umyuu commited on
Commit
39d2064
·
1 Parent(s): 4d72cd8

Google colab対応

Browse files

ウィジットの名称をmyappに変更

Files changed (2) hide show
  1. app.py +25 -19
  2. src/{app.py → myapp.py} +15 -14
app.py CHANGED
@@ -3,29 +3,35 @@
3
  SaliencyMapDemo
4
  """
5
  import argparse
6
- from datetime import datetime
7
 
8
- from utils import get_package_version, Stopwatch
9
- from reporter import get_current_reporter
 
 
 
10
 
11
  def main():
12
- """
13
- エントリーポイント
14
- 1, コマンドライン引数の解析を行います
15
- 2, アプリを起動します。
16
- """
17
- log = get_current_reporter()
18
- log.info("#アプリ起動中")
19
- watch = Stopwatch.startNew()
20
-
21
- import app
22
 
23
- parser = argparse.ArgumentParser(prog=app.PROGRAM_NAME, description="SaliencyMapDemo")
24
- parser.add_argument('--server_port', type=int, default=9999, help="Gradio server port")
25
- parser.add_argument('--max_file_size', type=int, default=20 * 1024 * 1024, help="Gradio max file size")
26
- parser.add_argument('--version', action='version', version=f'%(prog)s {get_package_version()}')
27
-
28
- app.run(parser.parse_args(), watch)
 
 
 
 
29
 
30
  if __name__ == "__main__":
31
  main()
 
3
  SaliencyMapDemo
4
  """
5
  import argparse
 
6
 
7
+ import src.utils as utils
8
+ from src.reporter import get_current_reporter
9
+
10
+ PROGRAM_NAME = 'SaliencyMapDemo'
11
+ __version__ = utils.get_package_version()
12
 
13
  def main():
14
+ """
15
+ エントリーポイント
16
+ 1, コマンドライン引数の解析を行います
17
+ 2, アプリを起動します。
18
+ """
19
+ log = get_current_reporter()
20
+ log.info("#アプリ起動中")
21
+ watch = utils.Stopwatch.startNew()
22
+
23
+ from src.myapp import runApp
24
 
25
+ parser = argparse.ArgumentParser(prog=PROGRAM_NAME, description="SaliencyMapDemo")
26
+ parser.add_argument('--server_port', type=int, default=9999, help="Gradio server port")
27
+ parser.add_argument('--max_file_size', type=int, default=20 * 1024 * 1024, help="Gradio max file size")
28
+ parser.add_argument('--inbrowser', type=bool, default=True, help="Gradio inbrowser")
29
+ parser.add_argument('--share', type=bool, default=False, help="Gradio share")
30
+ parser.add_argument('--version', action='version', version=f'%(prog)s {__version__}')
31
+
32
+ args = parser.parse_args()
33
+
34
+ runApp(args, watch)
35
 
36
  if __name__ == "__main__":
37
  main()
src/{app.py → myapp.py} RENAMED
@@ -1,7 +1,6 @@
1
  # -*- coding: utf-8 -*-
2
- """
3
- SaliencyMapDemo
4
- """
5
  import argparse
6
  from datetime import datetime
7
  import sys
@@ -9,14 +8,14 @@ import sys
9
  import gradio as gr
10
  import numpy as np
11
 
12
- import utils
13
- from saliency import SaliencyMap, convertColorMap
14
- from reporter import get_current_reporter
15
-
16
  PROGRAM_NAME = 'SaliencyMapDemo'
17
  __version__ = utils.get_package_version()
18
  log = get_current_reporter()
19
-
20
  def jetTab_Selected(image: np.ndarray):
21
  #print(f"{datetime.now()}#jet")
22
  saliency = SaliencyMap("SpectralResidual")
@@ -30,7 +29,7 @@ def hotTab_Selected(image: np.ndarray):
30
  #print(f"{datetime.now()}#hot")
31
  saliency = SaliencyMap("SpectralResidual")
32
  success, saliencyMap = saliency.computeSaliency(image)
33
- retval = convertColorMap(image, saliencyMap, "hot")
34
  #print(f"{datetime.now()}#hot")
35
 
36
  return retval
@@ -60,13 +59,14 @@ def submit_Clicked(image: np.ndarray, algorithm: str):
60
  jet = convertColorMap(image, saliencyMap, "jet")
61
  #jet = None
62
  log.info(f"#hot")
63
- hot = convertColorMap(image, saliencyMap, "hot")
64
 
65
  saliency = None
66
  log.info(f"#submit_Clicked End{watch.stop():.3f}")
 
67
  return jet, hot
68
 
69
- def run(args: argparse.Namespace, watch: utils.Stopwatch) -> None:
70
  """
71
  アプリの画面を作成し、Gradioサービスを起動します。
72
 
@@ -123,11 +123,12 @@ def run(args: argparse.Namespace, watch: utils.Stopwatch) -> None:
123
  demo.queue(default_concurrency_limit=5)
124
 
125
  log.info(f"#アプリ起動完了({watch.stop():.3f}s)")
126
-
127
  # https://www.gradio.app/docs/gradio/blocks#blocks-launch
 
128
  demo.launch(
129
  max_file_size=args.max_file_size,
130
  server_port=args.server_port,
131
- inbrowser=True,
132
- share=False,
133
  )
 
 
1
  # -*- coding: utf-8 -*-
2
+ from typing import Literal
3
+
 
4
  import argparse
5
  from datetime import datetime
6
  import sys
 
8
  import gradio as gr
9
  import numpy as np
10
 
11
+ import src.utils as utils
12
+ from src.saliency import SaliencyMap, convertColorMap
13
+ from src.reporter import get_current_reporter
14
+
15
  PROGRAM_NAME = 'SaliencyMapDemo'
16
  __version__ = utils.get_package_version()
17
  log = get_current_reporter()
18
+
19
  def jetTab_Selected(image: np.ndarray):
20
  #print(f"{datetime.now()}#jet")
21
  saliency = SaliencyMap("SpectralResidual")
 
29
  #print(f"{datetime.now()}#hot")
30
  saliency = SaliencyMap("SpectralResidual")
31
  success, saliencyMap = saliency.computeSaliency(image)
32
+ retval = convertColorMap(image, saliencyMap, "turbo")
33
  #print(f"{datetime.now()}#hot")
34
 
35
  return retval
 
59
  jet = convertColorMap(image, saliencyMap, "jet")
60
  #jet = None
61
  log.info(f"#hot")
62
+ hot = convertColorMap(image, saliencyMap, "turbo")
63
 
64
  saliency = None
65
  log.info(f"#submit_Clicked End{watch.stop():.3f}")
66
+
67
  return jet, hot
68
 
69
+ def runApp(args: argparse.Namespace, watch: utils.Stopwatch) -> None:
70
  """
71
  アプリの画面を作成し、Gradioサービスを起動します。
72
 
 
123
  demo.queue(default_concurrency_limit=5)
124
 
125
  log.info(f"#アプリ起動完了({watch.stop():.3f}s)")
 
126
  # https://www.gradio.app/docs/gradio/blocks#blocks-launch
127
+
128
  demo.launch(
129
  max_file_size=args.max_file_size,
130
  server_port=args.server_port,
131
+ inbrowser=args.inbrowser,
132
+ share=args.share,
133
  )
134
+