Cheomjee commited on
Commit
298c7fa
·
verified ·
1 Parent(s): e9a8362

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -37
app.py CHANGED
@@ -1,54 +1,25 @@
1
  import tensorflow as tf
2
  import gradio as gr
 
 
 
3
 
4
  # .h5 파일을 이용한 모델 로드
5
  model = tf.keras.models.load_model('path_to_your_model.h5')
6
 
7
  # 이미지 전처리 함수
8
  def preprocess_image(image):
9
- image = tf.image.resize(image, [224, 224]) # 모델에 맞게 이미지 크기 조정
10
- image = tf.cast(image, tf.float32) / 255.0 # 정규화
11
- image = tf.expand_dims(image, axis=0) # 배치 차원 추가
 
12
  return image
13
 
14
  # 예측 함수
15
  def predict(image):
16
  processed_image = preprocess_image(image)
17
  predictions = model.predict(processed_image)
18
- predicted_class = tf.argmax(predictions, axis=-1).numpy()[0]
19
- return predicted_class
20
-
21
- # Gradio 인터페이스 설정
22
- interface = gr.Interface(
23
- fn=predict,
24
- inputs=gr.inputs.Image(source="upload", tool="editor"),
25
- outputs="label",
26
- live=True
27
- )
28
-
29
- # Gradio 웹 인터페이스 실행
30
- if __name__ == "__main__":
31
- interface.launch()
32
-
33
-
34
- import tensorflow as tf
35
- import gradio as gr
36
-
37
- # .h5 파일을 이용한 모델 로드
38
- model = tf.keras.models.load_model('path_to_your_model.h5')
39
-
40
- # 이미지 전처리 함수
41
- def preprocess_image(image):
42
- image = tf.image.resize(image, [224, 224]) # 모델에 맞게 이미지 크기 조정
43
- image = tf.cast(image, tf.float32) / 255.0 # 정규화
44
- image = tf.expand_dims(image, axis=0) # 배치 차원 추가
45
- return image
46
-
47
- # 예측 함수
48
- def predict(image):
49
- processed_image = preprocess_image(image)
50
- predictions = model.predict(processed_image)
51
- predicted_class = tf.argmax(predictions, axis=-1).numpy()[0]
52
  return predicted_class
53
 
54
  # Gradio 인터페이스 설정
 
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('path_to_your_model.h5')
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
 
18
  # 예측 함수
19
  def predict(image):
20
  processed_image = preprocess_image(image)
21
  predictions = model.predict(processed_image)
22
+ predicted_class = np.argmax(predictions, axis=-1)[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  return predicted_class
24
 
25
  # Gradio 인터페이스 설정