Pichayada commited on
Commit
3a48c1b
·
verified ·
1 Parent(s): f4d48ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -1,3 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
  def generate_caption(image):
2
  if not isinstance(image, Image.Image):
3
  image = Image.fromarray(image)
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import torch
4
+ from PIL import Image
5
+ from transformers import AutoProcessor, AutoModelForCausalLM
6
+
7
+ subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
8
+
9
+ device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ florence_model = AutoModelForCausalLM.from_pretrained('microsoft/Florence-2-base', trust_remote_code=True).to(device).eval()
11
+ florence_processor = AutoProcessor.from_pretrained('microsoft/Florence-2-base', trust_remote_code=True)
12
+
13
  def generate_caption(image):
14
  if not isinstance(image, Image.Image):
15
  image = Image.fromarray(image)