File size: 1,007 Bytes
a2ec7ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb5c464
fd3d769
cc01dd1
a2ec7ce
 
432a30b
a2ec7ce
a65f024
a2ec7ce
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()