satyaaa-m commited on
Commit
bdeb045
·
verified ·
1 Parent(s): d4f2186

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -1,17 +1,20 @@
1
  import gradio as gr
2
  import os
3
 
4
- # Use a pipeline as a high-level helper
5
- # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5.
6
- # You must load the model directly (see below) or downgrade to v4.x with:
7
- # 'pip install "transformers<5.0.0'
8
- from transformers import pipeline
 
 
9
 
10
- pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
11
 
12
  def caption(image):
13
- out = pipe(image)
14
- return out[0]['generated_text']
 
 
15
 
16
  demo = gr.Interface(
17
  fn = caption,
 
1
  import gradio as gr
2
  import os
3
 
4
+ from transformers import BlipForConditionalGeneration
5
+ from transformers import AutoProcessor
6
+
7
+ model = BlipForConditionalGeneration.from_pretrained(
8
+ "./models/Salesforce/blip-image-captioning-base")
9
+ processor = AutoProcessor.from_pretrained(
10
+ "./models/Salesforce/blip-image-captioning-base")
11
 
 
12
 
13
  def caption(image):
14
+ inputs = processor(image,return_tensors="pt")
15
+ out = model.generate(**inputs)
16
+
17
+ return processor.decode(out[0], skip_special_tokens=True)
18
 
19
  demo = gr.Interface(
20
  fn = caption,