Spaces:
Runtime error
Runtime error
ShreyMehra
commited on
Commit
β’
ea4b257
1
Parent(s):
ea7519a
Update app.py
Browse files
app.py
CHANGED
@@ -28,8 +28,8 @@ class UI:
|
|
28 |
|
29 |
with st.spinner("π€ AI is at Work! "):
|
30 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
31 |
-
print(1)
|
32 |
-
inputs = processor(images=input_image, return_tensors="pt").to(device, torch.
|
33 |
|
34 |
print(2)
|
35 |
pixel_values = inputs.pixel_values
|
@@ -38,7 +38,7 @@ class UI:
|
|
38 |
# pixel_values = pixel_values.to(torch.float32)
|
39 |
|
40 |
print(3)
|
41 |
-
generated_ids = model.
|
42 |
|
43 |
print(4)
|
44 |
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
@@ -58,7 +58,7 @@ class Model:
|
|
58 |
def load_model(self):
|
59 |
global model
|
60 |
global processor
|
61 |
-
model = Blip2ForConditionalGeneration.from_pretrained("Shrey23/Image-Captioning",
|
62 |
processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
63 |
|
64 |
def main():
|
|
|
28 |
|
29 |
with st.spinner("π€ AI is at Work! "):
|
30 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
31 |
+
print(1, device)
|
32 |
+
inputs = processor(images=input_image, return_tensors="pt").to(device, torch.float16)
|
33 |
|
34 |
print(2)
|
35 |
pixel_values = inputs.pixel_values
|
|
|
38 |
# pixel_values = pixel_values.to(torch.float32)
|
39 |
|
40 |
print(3)
|
41 |
+
generated_ids = model.generate(pixel_values=pixel_values, max_length=25) #.to(device, torch.float32)
|
42 |
|
43 |
print(4)
|
44 |
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
|
|
58 |
def load_model(self):
|
59 |
global model
|
60 |
global processor
|
61 |
+
model = Blip2ForConditionalGeneration.from_pretrained("Shrey23/Image-Captioning", device_map="auto", load_in_8bit=True, torch_dtype=torch.float16) #,
|
62 |
processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
63 |
|
64 |
def main():
|