SixOpen commited on
Commit
23686dc
·
verified ·
1 Parent(s): 664d48c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -17
app.py CHANGED
@@ -1,9 +1,7 @@
1
  import os
2
- from unittest.mock import patch
3
  import spaces
4
  import gradio as gr
5
  from transformers import AutoProcessor, AutoModelForCausalLM
6
- from transformers.dynamic_module_utils import get_imports
7
  import torch
8
  from PIL import Image, ImageDraw
9
  import random
@@ -14,24 +12,19 @@ import cv2
14
  import io
15
  import uuid
16
 
17
- def workaround_fixed_get_imports(filename: str | os.PathLike) -> list[str]:
18
- if not str(filename).endswith("/modeling_florence2.py"):
19
- return get_imports(filename)
20
- imports = get_imports(filename)
21
- imports.remove("flash_attn")
22
- return imports
23
 
24
  def load_model():
25
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
26
- with patch("transformers.dynamic_module_utils.get_imports", workaround_fixed_get_imports):
27
- model = AutoModelForCausalLM.from_pretrained(
28
- "microsoft/Florence-2-large-ft",
29
- trust_remote_code=True
30
- ).to(device).eval()
31
- processor = AutoProcessor.from_pretrained(
32
- "microsoft/Florence-2-large-ft",
33
- trust_remote_code=True
34
- )
35
  return model, processor, device
36
 
37
  model = None
 
1
  import os
 
2
  import spaces
3
  import gradio as gr
4
  from transformers import AutoProcessor, AutoModelForCausalLM
 
5
  import torch
6
  from PIL import Image, ImageDraw
7
  import random
 
12
  import io
13
  import uuid
14
 
15
+ import subprocess
16
+ subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
 
 
 
 
17
 
18
  def load_model():
19
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
20
+ model = AutoModelForCausalLM.from_pretrained(
21
+ "microsoft/Florence-2-large-ft",
22
+ trust_remote_code=True
23
+ ).to(device).eval()
24
+ processor = AutoProcessor.from_pretrained(
25
+ "microsoft/Florence-2-large-ft",
26
+ trust_remote_code=True
27
+ )
 
28
  return model, processor, device
29
 
30
  model = None