crrrr30 commited on
Commit
cf39734
1 Parent(s): 9cbc0e0

Upload folder using huggingface_hub

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