aagoluoglu commited on
Commit
3549727
·
verified ·
1 Parent(s): b5d0536

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -8,6 +8,9 @@ import shinyswatch
8
 
9
  from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
10
 
 
 
 
11
  sns.set_theme()
12
 
13
  www_dir = Path(__file__).parent.resolve() / "www"
@@ -55,6 +58,17 @@ app_ui = ui.page_fillable(
55
 
56
 
57
  def server(input: Inputs, output: Outputs, session: Session):
 
 
 
 
 
 
 
 
 
 
 
58
  @reactive.Calc
59
  def uploaded_image_path() -> str:
60
  """Returns the path to the uploaded image"""
 
8
 
9
  from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
10
 
11
+ from transformers import SamModel, SamConfig, SamProcessor
12
+ import torch
13
+
14
  sns.set_theme()
15
 
16
  www_dir = Path(__file__).parent.resolve() / "www"
 
58
 
59
 
60
  def server(input: Inputs, output: Outputs, session: Session):
61
+ # Load the model configuration
62
+ model_config = SamConfig.from_pretrained("facebook/sam-vit-base")
63
+ processor = SamProcessor.from_pretrained("facebook/sam-vit-base")
64
+
65
+ # Create an instance of the model from my fine-tuned model with the loaded configuration
66
+ model = SamModel.from_pretrained("aagoluoglu/SAM_Sidewalks", config=model_config)
67
+
68
+ # set the device to cuda if available, otherwise use cpu
69
+ device = "cuda" if torch.cuda.is_available() else "cpu"
70
+ model.to(device)
71
+
72
  @reactive.Calc
73
  def uploaded_image_path() -> str:
74
  """Returns the path to the uploaded image"""