Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,9 @@ import PIL.Image
|
|
| 17 |
import tensorflow as tf
|
| 18 |
import piexif
|
| 19 |
import piexif.helper
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
TITLE = 'DeepDanbooru String'
|
| 22 |
|
|
@@ -68,8 +71,12 @@ def plaintext_to_html(text):
|
|
| 68 |
text = "<p>" + "<br>\n".join([f"{html.escape(x)}" for x in text.split('\n')]) + "</p>"
|
| 69 |
return text
|
| 70 |
|
| 71 |
-
def predict(
|
| 72 |
model: tf.keras.Model, labels: list[str]) -> dict[str, float]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
rawimage = image
|
| 74 |
_, height, width, _ = model.input_shape
|
| 75 |
image = np.asarray(image)
|
|
@@ -140,7 +147,7 @@ def main():
|
|
| 140 |
gr.Interface(
|
| 141 |
func,
|
| 142 |
[
|
| 143 |
-
gr.inputs.
|
| 144 |
gr.inputs.Slider(0,
|
| 145 |
1,
|
| 146 |
step=args.score_slider_step,
|
|
|
|
| 17 |
import tensorflow as tf
|
| 18 |
import piexif
|
| 19 |
import piexif.helper
|
| 20 |
+
import requests
|
| 21 |
+
from io import BytesIO
|
| 22 |
+
from PIL import Image
|
| 23 |
|
| 24 |
TITLE = 'DeepDanbooru String'
|
| 25 |
|
|
|
|
| 71 |
text = "<p>" + "<br>\n".join([f"{html.escape(x)}" for x in text.split('\n')]) + "</p>"
|
| 72 |
return text
|
| 73 |
|
| 74 |
+
def predict(image_url:str, score_threshold: float,
|
| 75 |
model: tf.keras.Model, labels: list[str]) -> dict[str, float]:
|
| 76 |
+
response = requests.get(image_url)
|
| 77 |
+
|
| 78 |
+
# 将图片内容转换为Pillow.Image对象
|
| 79 |
+
image = Image.open(BytesIO(response.content))
|
| 80 |
rawimage = image
|
| 81 |
_, height, width, _ = model.input_shape
|
| 82 |
image = np.asarray(image)
|
|
|
|
| 147 |
gr.Interface(
|
| 148 |
func,
|
| 149 |
[
|
| 150 |
+
gr.inputs.Textbox( label='Inputurl'),
|
| 151 |
gr.inputs.Slider(0,
|
| 152 |
1,
|
| 153 |
step=args.score_slider_step,
|