siriuszeina commited on
Commit
a745ac1
·
verified ·
1 Parent(s): eee050e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -13,6 +13,7 @@ import huggingface_hub
13
  import numpy as np
14
  import PIL.Image
15
  import tensorflow as tf
 
16
 
17
  DESCRIPTION = "# [KichangKim/DeepDanbooru](https://github.com/KichangKim/DeepDanbooru)"
18
 
@@ -43,10 +44,10 @@ model = load_model()
43
  labels = load_labels()
44
 
45
  #image: PIL.Image.Image
46
- def predict(image: PIL.Image.Image, score_threshold: float) -> tuple[dict[str, float], dict[str, float], str]:
47
  _, height, width, _ = model.input_shape
48
- #response = requests.get(url)
49
- #image = PIL.Image.open(img)
50
 
51
  image = np.asarray(image)
52
  image = tf.image.resize(image, size=(height, width), method=tf.image.ResizeMethod.AREA, preserve_aspect_ratio=True)
@@ -77,8 +78,8 @@ with gr.Blocks(css="style.css") as demo:
77
  gr.Markdown(DESCRIPTION)
78
  with gr.Row():
79
  with gr.Column():
80
- image = gr.Image(label="Input", type="pil")
81
- #url = gr.Textbox("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png")
82
  #img = gr.File(type="binary")
83
  score_threshold = gr.Slider(label="Score threshold", minimum=0, maximum=1, step=0.05, value=0.5)
84
  run_button = gr.Button("Run")
@@ -93,7 +94,7 @@ with gr.Blocks(css="style.css") as demo:
93
 
94
  run_button.click(
95
  fn=predict,
96
- inputs=[image, score_threshold],
97
  outputs=[result, result_json, result_text],
98
  api_name="predict",
99
  )
 
13
  import numpy as np
14
  import PIL.Image
15
  import tensorflow as tf
16
+ import base64
17
 
18
  DESCRIPTION = "# [KichangKim/DeepDanbooru](https://github.com/KichangKim/DeepDanbooru)"
19
 
 
44
  labels = load_labels()
45
 
46
  #image: PIL.Image.Image
47
+ def predict(base: str, score_threshold: float) -> tuple[dict[str, float], dict[str, float], str]:
48
  _, height, width, _ = model.input_shape
49
+
50
+ image = PIL.Image.open(BytesIO(base64.b64decode(base)))
51
 
52
  image = np.asarray(image)
53
  image = tf.image.resize(image, size=(height, width), method=tf.image.ResizeMethod.AREA, preserve_aspect_ratio=True)
 
78
  gr.Markdown(DESCRIPTION)
79
  with gr.Row():
80
  with gr.Column():
81
+ #image = gr.Image(label="Input", type="pil")
82
+ base = gr.Textbox("")
83
  #img = gr.File(type="binary")
84
  score_threshold = gr.Slider(label="Score threshold", minimum=0, maximum=1, step=0.05, value=0.5)
85
  run_button = gr.Button("Run")
 
94
 
95
  run_button.click(
96
  fn=predict,
97
+ inputs=[base, score_threshold],
98
  outputs=[result, result_json, result_text],
99
  api_name="predict",
100
  )