crrrr30 commited on
Commit
391e183
1 Parent(s): d5a3c94

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. demo.py +4 -7
demo.py CHANGED
@@ -89,10 +89,7 @@ def predict(inp):
89
 
90
  print(f"=> Model (tpmlp_{size}) loaded in {time.time()- start:.2f} sec(s).")
91
 
92
- base = ".." if args.local else "."
93
-
94
- if not os.path.isdir(f"{base}/example-imgs"):
95
- os.mkdir(f"{base}/example-imgs")
96
 
97
  print("=> Loading examples.")
98
  indices = [
@@ -110,7 +107,7 @@ examples = []; idx = 0
110
  start = time.time()
111
  for data in ds:
112
  if idx == indices:
113
- data['image'].save(f"{base}/example-imgs/{idx}.png")
114
  idx += 1
115
  if idx == max(indices):
116
  break
@@ -139,9 +136,9 @@ with gr.Blocks(theme=gr.themes.Monochrome(font=[gr.themes.GoogleFont("DM Sans"),
139
  gr.Button("Predict").click(fn=predict, inputs=input_image, outputs=[softmax, grad_cam])
140
  gr.ClearButton(input_image)
141
  with gr.Row():
142
- gr.Examples([f"{base}/example-imgs/{idx}.png" for idx in indices], inputs=input_image, outputs=[softmax, grad_cam], fn=predict, run_on_click=True)
143
 
144
  demo.launch(
145
- share=False, debug=False, allowed_paths=[f"{base}/example-imgs"], server_name="0.0.0.0", # ssl_verify=False,
146
  server_port=8000, # ssl_certfile="/workspace/openssl/cert.pem", ssl_keyfile="/workspace/openssl/key.pem"
147
  )
 
89
 
90
  print(f"=> Model (tpmlp_{size}) loaded in {time.time()- start:.2f} sec(s).")
91
 
92
+ base = "../example-imgs" if args.local else "."
 
 
 
93
 
94
  print("=> Loading examples.")
95
  indices = [
 
107
  start = time.time()
108
  for data in ds:
109
  if idx == indices:
110
+ data['image'].save(f"{base}/{idx}.png")
111
  idx += 1
112
  if idx == max(indices):
113
  break
 
136
  gr.Button("Predict").click(fn=predict, inputs=input_image, outputs=[softmax, grad_cam])
137
  gr.ClearButton(input_image)
138
  with gr.Row():
139
+ gr.Examples([f"{base}/{idx}.png" for idx in indices], inputs=input_image, outputs=[softmax, grad_cam], fn=predict, run_on_click=True)
140
 
141
  demo.launch(
142
+ share=False, debug=False, allowed_paths=[f"{base}"], server_name="0.0.0.0", # ssl_verify=False,
143
  server_port=8000, # ssl_certfile="/workspace/openssl/cert.pem", ssl_keyfile="/workspace/openssl/key.pem"
144
  )