ifmain commited on
Commit
7cbee76
1 Parent(s): 4e2c724

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -1,9 +1,6 @@
1
- # Yolo (before mod-spaces)
2
- from ultralytics import YOLO
3
-
4
  # UI and Application Framework
5
  import gradio as gr
6
- import spaces # Thanks a lot!
7
 
8
 
9
  # Standard Libraries
@@ -19,18 +16,23 @@ from PIL import Image
19
  import torch
20
  from transformers import pipeline
21
  from diffusers import AutoPipelineForInpainting
 
22
 
23
  # Text and Data Manipulation
24
  import difflib
25
 
26
 
 
 
27
 
 
 
28
  yoloModel = YOLO('yolov8x-seg.pt')
29
  sdxl = AutoPipelineForInpainting.from_pretrained(
30
  "diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
31
- torch_dtype=torch.float16
32
- )
33
- image_captioner = pipeline("image-to-text", model="Abdou/vit-swin-base-224-gpt2-image-captioning")
34
 
35
 
36
  def image_to_base64(image: Image.Image):
@@ -54,7 +56,7 @@ def get_most_similar_string(target_string, string_array):
54
 
55
  # Yolo
56
  def getClasses(model, img1):
57
- results = model([np.array(img1)])
58
  out = []
59
  for r in results:
60
  im_array = r.plot()
@@ -106,7 +108,6 @@ def getSegments(yoloModel, img1):
106
  return allMask
107
 
108
 
109
-
110
  # Gradio UI
111
  @spaces.GPU
112
  def captionMaker(base64_img):
@@ -165,4 +166,4 @@ iface = gr.Interface(
165
  live=False
166
  )
167
 
168
- iface.launch()
 
 
 
 
1
  # UI and Application Framework
2
  import gradio as gr
3
+ import spaces
4
 
5
 
6
  # Standard Libraries
 
16
  import torch
17
  from transformers import pipeline
18
  from diffusers import AutoPipelineForInpainting
19
+ from ultralytics import YOLO
20
 
21
  # Text and Data Manipulation
22
  import difflib
23
 
24
 
25
+ # Constants
26
+ DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
27
 
28
+ # Load
29
+ DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
30
  yoloModel = YOLO('yolov8x-seg.pt')
31
  sdxl = AutoPipelineForInpainting.from_pretrained(
32
  "diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
33
+ torch_dtype=torch.float32
34
+ ).to(DEVICE)
35
+ image_captioner = pipeline("image-to-text", model="Abdou/vit-swin-base-224-gpt2-image-captioning", device=DEVICE)
36
 
37
 
38
  def image_to_base64(image: Image.Image):
 
56
 
57
  # Yolo
58
  def getClasses(model, img1):
59
+ results = model([np.array(img1)]) # Изменение для передачи изображения как массива NumPy
60
  out = []
61
  for r in results:
62
  im_array = r.plot()
 
108
  return allMask
109
 
110
 
 
111
  # Gradio UI
112
  @spaces.GPU
113
  def captionMaker(base64_img):
 
166
  live=False
167
  )
168
 
169
+ iface.launch()