arad1367 commited on
Commit
219a1a5
1 Parent(s): 49da751

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -6,6 +6,7 @@ import gradio as gr
6
  from transformers import AutoProcessor, AutoModelForCausalLM
7
  import torch
8
  import numpy as np
 
9
  import subprocess
10
 
11
  subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
@@ -33,6 +34,7 @@ def preprocess_image(image_path, max_size=(800, 800)):
33
  return image_np, image.size
34
 
35
  # Function to run Florence-2-large model
 
36
  def run_florence_model(image_np, image_size, task_prompt, text_input=None):
37
  if text_input is None:
38
  prompt = task_prompt
@@ -62,11 +64,9 @@ def run_florence_model(image_np, image_size, task_prompt, text_input=None):
62
 
63
  # Function to plot image with bounding boxes
64
  def plot_image_with_bboxes(image_np, bboxes, labels=None):
65
- # Normalize the image array to [0.0, 1.0]
66
- if image_np.dtype == np.uint8:
67
- image_np = image_np / 255.0
68
-
69
  fig, ax = plt.subplots(1)
 
 
70
  ax.imshow(image_np)
71
  colors = ['red', 'blue', 'green', 'yellow', 'purple', 'cyan']
72
  for i, bbox in enumerate(bboxes):
@@ -80,9 +80,10 @@ def plot_image_with_bboxes(image_np, bboxes, labels=None):
80
  return fig
81
 
82
  # Gradio function to process uploaded images
 
83
  def process_image(image_path):
84
  image_np, image_size = preprocess_image(image_path)
85
-
86
  # Convert image_np to float32
87
  image_np = image_np.astype(np.float32)
88
 
 
6
  from transformers import AutoProcessor, AutoModelForCausalLM
7
  import torch
8
  import numpy as np
9
+ import spaces
10
  import subprocess
11
 
12
  subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
 
34
  return image_np, image.size
35
 
36
  # Function to run Florence-2-large model
37
+ @spaces.GPU
38
  def run_florence_model(image_np, image_size, task_prompt, text_input=None):
39
  if text_input is None:
40
  prompt = task_prompt
 
64
 
65
  # Function to plot image with bounding boxes
66
  def plot_image_with_bboxes(image_np, bboxes, labels=None):
 
 
 
 
67
  fig, ax = plt.subplots(1)
68
+ # Normalize the image data to the range [0, 1]
69
+ image_np = image_np / 255.0
70
  ax.imshow(image_np)
71
  colors = ['red', 'blue', 'green', 'yellow', 'purple', 'cyan']
72
  for i, bbox in enumerate(bboxes):
 
80
  return fig
81
 
82
  # Gradio function to process uploaded images
83
+ @spaces.GPU
84
  def process_image(image_path):
85
  image_np, image_size = preprocess_image(image_path)
86
+
87
  # Convert image_np to float32
88
  image_np = image_np.astype(np.float32)
89