hexgrad commited on
Commit
d96f8ab
1 Parent(s): a315cb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -7,9 +7,10 @@
7
  import gradio as gr
8
  from transformers import AutoProcessor, Idefics3ForConditionalGeneration, image_utils
9
  import torch
 
10
 
11
  # Determine the device (GPU or CPU) to run the model on
12
- device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
13
  print(f"Using device: {device}") # Log the device being used
14
 
15
  # Define the model ID and base model path
@@ -28,6 +29,7 @@ model = Idefics3ForConditionalGeneration.from_pretrained(
28
  model.load_adapter(model_id, device_map="auto")
29
 
30
  # Define a function to infer a description from an image
 
31
  def infere(image):
32
  """
33
  Generate a description of a medical image.
@@ -77,7 +79,7 @@ def infere(image):
77
  title = f"<a href='https://huggingface.co/eltorio/IDEFICS3_ROCO'>IDEFICS3_ROCO</a>: Medical Image to Text <b>running on {device}</b>"
78
  desc = "This model generates a description of a medical image."
79
 
80
- device_desc = f"This model is running on {device} 🚀." if device == torch.device('cuda') else f"🐢 This model is running on {device} it will be very (very) slow. If you can donate some GPU time it will be usable 🐢. <a href='https://huggingface.co/eltorio/IDEFICS3_ROCO/discussions'>Please contact us.</a>"
81
 
82
  # Define the long description for the Gradio interface
83
  long_desc = f"This demo is based on the <a href='https://huggingface.co/eltorio/IDEFICS3_ROCO'>IDEFICS3_ROCO model</a>, which is a multimodal model that can generate text from images. It has been fine-tuned on <a href='https://huggingface.co/datasets/eltorio/ROCO-radiology'>eltorio/ROCO-radiology</a>&nbsp;a dataset of medical images and can generate descriptions of medical images. Try uploading an image of a medical image and see what the model generates!<br><b>{device_desc}</b><br> 2024 - Ronan Le Meillat"
 
7
  import gradio as gr
8
  from transformers import AutoProcessor, Idefics3ForConditionalGeneration, image_utils
9
  import torch
10
+ import spaces
11
 
12
  # Determine the device (GPU or CPU) to run the model on
13
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
14
  print(f"Using device: {device}") # Log the device being used
15
 
16
  # Define the model ID and base model path
 
29
  model.load_adapter(model_id, device_map="auto")
30
 
31
  # Define a function to infer a description from an image
32
+ @spaces.GPU
33
  def infere(image):
34
  """
35
  Generate a description of a medical image.
 
79
  title = f"<a href='https://huggingface.co/eltorio/IDEFICS3_ROCO'>IDEFICS3_ROCO</a>: Medical Image to Text <b>running on {device}</b>"
80
  desc = "This model generates a description of a medical image."
81
 
82
+ device_desc = f"This model is running on {device} 🚀." if device == 'cuda' else f"🐢 This model is running on {device} it will be very (very) slow. If you can donate some GPU time it will be usable 🐢. <a href='https://huggingface.co/eltorio/IDEFICS3_ROCO/discussions'>Please contact us.</a>"
83
 
84
  # Define the long description for the Gradio interface
85
  long_desc = f"This demo is based on the <a href='https://huggingface.co/eltorio/IDEFICS3_ROCO'>IDEFICS3_ROCO model</a>, which is a multimodal model that can generate text from images. It has been fine-tuned on <a href='https://huggingface.co/datasets/eltorio/ROCO-radiology'>eltorio/ROCO-radiology</a>&nbsp;a dataset of medical images and can generate descriptions of medical images. Try uploading an image of a medical image and see what the model generates!<br><b>{device_desc}</b><br> 2024 - Ronan Le Meillat"