tykimos's picture
Update app.py
bb5c464
raw
history blame
1.01 kB
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 = 0.845
return {'์ •์ƒ': float(1-prediction), '๊ฐ์—ผ': float(prediction)}
# ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
imagein = gr.inputs.Image(type="pil")
label = gr.outputs.Label(num_top_classes=2)
# ์˜ˆ์ธก ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
gr.Interface(fn=predict_image, inputs=imagein, outputs=label,
title='์†Œ๋‚˜๋ฌด์žฌ์„ ์ถฉ๋ณ‘ ๊ฐ์—ผ ์—ฌ๋ถ€ ์˜ˆ์ธก',
description='์‚ฐ๋ฆผ์ฒญ์—์„œ ์ œ๊ณตํ•˜๋Š” ์†Œ๋‚˜๋ฌด์žฌ์„ ์ถฉ๋ณ‘ ๋ฐ์ดํ„ฐ์…‹์„ ์ด์šฉํ•œ ๋”ฅ๋Ÿฌ๋‹ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ์—ผ ์—ฌ๋ถ€๋ฅผ ์˜ˆ์ธกํ•ฉ๋‹ˆ๋‹ค.').launch()