Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# Load the model and tokenizer
|
2 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
3 |
model = AutoModelForVision2Seq.from_pretrained("stabilityai/japanese-stable-vlm", trust_remote_code=True, device_map='auto')
|
@@ -32,6 +42,7 @@ def build_prompt(task="caption", input=None, sep="\n\n### "):
|
|
32 |
return p
|
33 |
|
34 |
# Define the function to generate text from the image and prompt
|
|
|
35 |
def generate_text(image, task, input_text=None):
|
36 |
prompt = build_prompt(task=task, input=input_text)
|
37 |
inputs = processor(images=image, return_tensors="pt")
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForVision2Seq, AutoImageProcessor
|
4 |
+
from PIL import Image
|
5 |
+
import spaces
|
6 |
+
import os
|
7 |
+
|
8 |
+
from huggingface_hub import login
|
9 |
+
login(os.environ["HF_KEY"])
|
10 |
+
|
11 |
# Load the model and tokenizer
|
12 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
13 |
model = AutoModelForVision2Seq.from_pretrained("stabilityai/japanese-stable-vlm", trust_remote_code=True, device_map='auto')
|
|
|
42 |
return p
|
43 |
|
44 |
# Define the function to generate text from the image and prompt
|
45 |
+
@spaces.GPU(duration=120)
|
46 |
def generate_text(image, task, input_text=None):
|
47 |
prompt = build_prompt(task=task, input=input_text)
|
48 |
inputs = processor(images=image, return_tensors="pt")
|