tykimos's picture
Update app.py
a2ec7ce
raw
history blame
996 Bytes
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
import requests
from io import BytesIO
# ๋ชจ๋ธ ๋กœ๋“œ
model = tf.keras.models.load_model("my_model.h5")
# ์ด๋ฏธ์ง€๋ฅผ ์ „์ฒ˜๋ฆฌํ•˜๋Š” ํ•จ์ˆ˜
def preprocess(image):
img = image.resize((256, 256))
img = np.array(img)
img = img / 255.0
img = img.reshape((1,) + img.shape)
return img
# ์˜ˆ์ธก ํ•จ์ˆ˜
def predict_image(img):
img = preprocess(img)
prediction = model.predict(img)[0][0]
return {'์ •์ƒ': 1-prediction, '๊ฐ์—ผ': prediction}
# ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
imagein = gr.inputs.Image()
label = gr.outputs.Label(num_top_classes=2)
# ์˜ˆ์ธก ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
gr.Interface(fn=predict_image, inputs=imagein, outputs=label,
title='์†Œ๋‚˜๋ฌด์žฌ์„ ์ถฉ๋ณ‘ ๊ฐ์—ผ ์—ฌ๋ถ€ ์˜ˆ์ธก',
description='์‚ฐ๋ฆผ์ฒญ์—์„œ ์ œ๊ณตํ•˜๋Š” ์†Œ๋‚˜๋ฌด์žฌ์„ ์ถฉ๋ณ‘ ๋ฐ์ดํ„ฐ์…‹์„ ์ด์šฉํ•œ ๋”ฅ๋Ÿฌ๋‹ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ์—ผ ์—ฌ๋ถ€๋ฅผ ์˜ˆ์ธกํ•ฉ๋‹ˆ๋‹ค.').launch()