Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,19 @@
|
|
| 1 |
import tensorflow as tf
|
| 2 |
import gradio as gr
|
| 3 |
-
from transformers import ViTFeatureExtractor
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
# .h5 파일을 이용한 모델 로드
|
| 8 |
-
model = tf.keras.models.load_model('
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# 이미지 전처리 함수
|
| 11 |
def preprocess_image(image):
|
| 12 |
image = Image.fromarray(image)
|
| 13 |
-
image = image.resize((224, 224))
|
| 14 |
-
image = np.array(image) / 255.0
|
| 15 |
image = np.expand_dims(image, axis=0)
|
| 16 |
return image
|
| 17 |
|
|
@@ -19,14 +21,15 @@ def preprocess_image(image):
|
|
| 19 |
def predict(image):
|
| 20 |
processed_image = preprocess_image(image)
|
| 21 |
predictions = model.predict(processed_image)
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
# Gradio 인터페이스 설정
|
| 26 |
interface = gr.Interface(
|
| 27 |
fn=predict,
|
| 28 |
-
inputs=gr.
|
| 29 |
-
outputs=
|
| 30 |
live=True
|
| 31 |
)
|
| 32 |
|
|
|
|
| 1 |
import tensorflow as tf
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
# .h5 파일을 이용한 모델 로드
|
| 7 |
+
model = tf.keras.models.load_model('path_to_your_model.h5')
|
| 8 |
+
|
| 9 |
+
# 클래스 레이블 (예: 0은 'cat', 1은 'dog' 등)
|
| 10 |
+
class_labels = ['disposablecup', 'envmark', 'label','mug','nonlabel','reusablecup'] # 모델에 맞게 수정하세요.
|
| 11 |
|
| 12 |
# 이미지 전처리 함수
|
| 13 |
def preprocess_image(image):
|
| 14 |
image = Image.fromarray(image)
|
| 15 |
+
image = image.resize((224, 224)) # 모델 입력 크기에 맞게 조정
|
| 16 |
+
image = np.array(image) / 255.0 # 정규화
|
| 17 |
image = np.expand_dims(image, axis=0)
|
| 18 |
return image
|
| 19 |
|
|
|
|
| 21 |
def predict(image):
|
| 22 |
processed_image = preprocess_image(image)
|
| 23 |
predictions = model.predict(processed_image)
|
| 24 |
+
predicted_class_index = np.argmax(predictions, axis=-1)[0]
|
| 25 |
+
predicted_class_label = class_labels[predicted_class_index]
|
| 26 |
+
return predicted_class_label
|
| 27 |
|
| 28 |
# Gradio 인터페이스 설정
|
| 29 |
interface = gr.Interface(
|
| 30 |
fn=predict,
|
| 31 |
+
inputs=gr.Image(source="webcam", tool="editor"),
|
| 32 |
+
outputs=gr.Textbox(label="Predicted Class"),
|
| 33 |
live=True
|
| 34 |
)
|
| 35 |
|