Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
# Define the prediction function for Gradio
|
5 |
def predict(image, question):
|
6 |
inputs = processor(text=[question], images=[image], return_tensors="pt", padding=True).to(device)
|
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
3 |
|
4 |
+
|
5 |
+
from transformers import AutoConfig, AutoModelForCausalLM
|
6 |
+
import torch
|
7 |
+
|
8 |
+
# Determine if a GPU is available and set the device accordingly
|
9 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
10 |
+
|
11 |
+
|
12 |
+
# Load configuration from the base model
|
13 |
+
config = AutoConfig.from_pretrained("microsoft/Florence-2-base-ft", trust_remote_code=True)
|
14 |
+
|
15 |
+
# Load the model using the base model's configuration
|
16 |
+
model = AutoModelForCausalLM.from_pretrained(
|
17 |
+
"fauzail/Florence-2-VQA",
|
18 |
+
config=config,
|
19 |
+
trust_remote_code=True
|
20 |
+
).to(device)
|
21 |
+
|
22 |
+
from transformers import AutoProcessor
|
23 |
+
# Load the processor for the model
|
24 |
+
processor = AutoProcessor.from_pretrained("fauzail/Florence-2-VQA", trust_remote_code=True)
|
25 |
+
|
26 |
# Define the prediction function for Gradio
|
27 |
def predict(image, question):
|
28 |
inputs = processor(text=[question], images=[image], return_tensors="pt", padding=True).to(device)
|