git.name commited on
Commit
95d3331
·
1 Parent(s): 0bdc37b

initial commit

Browse files
Files changed (4) hide show
  1. app.py +22 -0
  2. images/christmas_dog.jpeg +0 -0
  3. images/cow.jpeg +0 -0
  4. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Define the task and model for the pipeline
5
+ task = 'image-to-text'
6
+ model = 'Salesforce/blip-image-captioning-base'
7
+ caption_pipeline = pipeline(task=task, model=model, max_new_tokens=100)
8
+
9
+ def get_caption(image):
10
+ # Directly pass the PIL image to the pipeline
11
+ result = caption_pipeline(image)
12
+ return result[0]['generated_text']
13
+
14
+ # Create a Gradio interface
15
+ result = gr.Interface(fn=get_caption,
16
+ inputs=[gr.Image(label="Upload Image", type="pil")],
17
+ outputs="text",
18
+ examples=['./images/cow.jpeg', './images/christmas_dog.jpeg']
19
+ )
20
+
21
+ # Launch the interface
22
+ result.launch(inline=False)
images/christmas_dog.jpeg ADDED
images/cow.jpeg ADDED
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ transformers