satyaaa-m commited on
Commit
db39d96
·
verified ·
1 Parent(s): 4698781

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -1,24 +1,21 @@
1
  import gradio as gr
2
  import os
3
-
4
- # Load model directly
5
  from transformers import AutoProcessor, AutoModelForImageTextToText
6
 
 
7
  processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
8
  model = AutoModelForImageTextToText.from_pretrained("Salesforce/blip-image-captioning-base")
9
 
10
-
11
  def caption(image):
12
- inputs = processor(image,return_tensors="pt")
 
13
  out = model.generate(**inputs)
14
-
15
  return processor.decode(out[0], skip_special_tokens=True)
16
 
17
  demo = gr.Interface(
18
- fn = caption,
19
- inputs = gr.Image(label = "Upload Image", type = "filepath"),
20
- outputs = "text"
21
  )
22
 
23
- demo.launch(share=True,
24
- server_port=int(os.environ['PORT1']))
 
1
  import gradio as gr
2
  import os
 
 
3
  from transformers import AutoProcessor, AutoModelForImageTextToText
4
 
5
+ # Load model and processor
6
  processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
7
  model = AutoModelForImageTextToText.from_pretrained("Salesforce/blip-image-captioning-base")
8
 
 
9
  def caption(image):
10
+ # 'image' is now a PIL Image object because of type="pil"
11
+ inputs = processor(image, return_tensors="pt")
12
  out = model.generate(**inputs)
 
13
  return processor.decode(out[0], skip_special_tokens=True)
14
 
15
  demo = gr.Interface(
16
+ fn=caption,
17
+ inputs=gr.Image(label="Upload Image", type="pil"),
18
+ outputs="text"
19
  )
20
 
21
+ demo.launch()