seawolf2357 commited on
Commit
3382a71
โ€ข
1 Parent(s): 3ec95cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -6,6 +6,12 @@ from PIL import Image
6
  model = pipeline("image-classification", model="google/vit-base-patch16-224")
7
 
8
  def classify_image(uploaded_image):
 
 
 
 
 
 
9
  predictions = model(uploaded_image)
10
  return {prediction['label']: prediction['score'] for prediction in predictions}
11
 
@@ -16,6 +22,5 @@ iface = gr.Interface(fn=classify_image,
16
  title="์ด๋ฏธ์ง€ ๋ถ„๋ฅ˜๊ธฐ",
17
  description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋ฉด, ์‚ฌ๋ฌผ์„ ์ธ์‹ํ•˜๊ณ  ์ตœ์ƒ์œ„ 3๊ฐœ์˜ ๋ถ„๋ฅ˜ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.")
18
 
19
- # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰ ๋ฐ ๊ณต๊ฐœ ๋งํฌ ์ƒ์„ฑ
20
- iface.launch(share=True)
21
-
 
6
  model = pipeline("image-classification", model="google/vit-base-patch16-224")
7
 
8
  def classify_image(uploaded_image):
9
+ # ์—…๋กœ๋“œ๋œ ์ด๋ฏธ์ง€๊ฐ€ PIL ์ด๋ฏธ์ง€ ๊ฐ์ฒด๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ ๋ณ€ํ™˜
10
+ if not isinstance(uploaded_image, Image.Image):
11
+ # ์—…๋กœ๋“œ๋œ ์ด๋ฏธ์ง€๊ฐ€ PIL ์ด๋ฏธ์ง€ ๊ฐ์ฒด๊ฐ€ ์•„๋‹ˆ๋ฉด, ์ด ๋ถ€๋ถ„์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋กœ์ง ์ถ”๊ฐ€
12
+ # ์˜ˆ: uploaded_image = Image.open(io.BytesIO(uploaded_image))
13
+ raise ValueError("Uploaded image is not a PIL Image object.")
14
+
15
  predictions = model(uploaded_image)
16
  return {prediction['label']: prediction['score'] for prediction in predictions}
17
 
 
22
  title="์ด๋ฏธ์ง€ ๋ถ„๋ฅ˜๊ธฐ",
23
  description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋ฉด, ์‚ฌ๋ฌผ์„ ์ธ์‹ํ•˜๊ณ  ์ตœ์ƒ์œ„ 3๊ฐœ์˜ ๋ถ„๋ฅ˜ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.")
24
 
25
+ # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
26
+ iface.launch()