Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
import requests
|
6 |
+
from io import BytesIO
|
7 |
+
|
8 |
+
# ๋ชจ๋ธ ๋ก๋
|
9 |
+
model = tf.keras.models.load_model("my_model.h5")
|
10 |
+
|
11 |
+
# ์ด๋ฏธ์ง๋ฅผ ์ ์ฒ๋ฆฌํ๋ ํจ์
|
12 |
+
def preprocess(image):
|
13 |
+
img = image.resize((256, 256))
|
14 |
+
img = np.array(img)
|
15 |
+
img = img / 255.0
|
16 |
+
img = img.reshape((1,) + img.shape)
|
17 |
+
return img
|
18 |
+
|
19 |
+
# ์์ธก ํจ์
|
20 |
+
def predict_image(img):
|
21 |
+
img = preprocess(img)
|
22 |
+
prediction = model.predict(img)[0][0]
|
23 |
+
return {'์ ์': 1-prediction, '๊ฐ์ผ': prediction}
|
24 |
+
|
25 |
+
# ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
26 |
+
imagein = gr.inputs.Image()
|
27 |
+
label = gr.outputs.Label(num_top_classes=2)
|
28 |
+
|
29 |
+
# ์์ธก ์ธํฐํ์ด์ค ์คํ
|
30 |
+
gr.Interface(fn=predict_image, inputs=imagein, outputs=label,
|
31 |
+
title='์๋๋ฌด์ฌ์ ์ถฉ๋ณ ๊ฐ์ผ ์ฌ๋ถ ์์ธก',
|
32 |
+
description='์ฐ๋ฆผ์ฒญ์์ ์ ๊ณตํ๋ ์๋๋ฌด์ฌ์ ์ถฉ๋ณ ๋ฐ์ดํฐ์
์ ์ด์ฉํ ๋ฅ๋ฌ๋ ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ๊ฐ์ผ ์ฌ๋ถ๋ฅผ ์์ธกํฉ๋๋ค.').launch()
|