tykimos commited on
Commit
a2ec7ce
ยท
1 Parent(s): 84c1774

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
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()