shaaravpawar commited on
Commit
d2a848f
·
verified ·
1 Parent(s): dc7bd5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -1,14 +1,17 @@
1
- from diffusers import DiffusionPipeline
2
  import gradio as gr
3
- model_id = "CompVis/ldm-text2im-large-256"
4
- ldm = DiffusionPipeline.from_pretrained(model_id)
5
-
6
-
7
- def generate_image(Prompt):
8
- images = ldm([Prompt], num_inference_steps=50, eta=.3, guidance_scale=6)
9
- return images.images[0]
10
-
11
-
12
- interface = gr.Interface(fn = generate_image,inputs = "text",outputs = "image",title = "Mashdemy Demo Image Generator App", description = "Type in a text and click submit to generate an image:", examples = ["a clown reading a book", "a cat using a laptop", "An elephant on grass"])
13
-
14
- interface.launch(share = True)
 
 
 
 
1
+ from transformers import pipeline
2
  import gradio as gr
3
+ from PIL import Image
4
+ pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
5
+ def generate_caption(image):
6
+ # Generate a caption for the image
7
+ captions = pipe(image)
8
+ return captions[0]['generated_text']
9
+ demo = gr.Interface(
10
+ fn=generate_caption,
11
+ inputs=gr.Image(type="pil", label="Upload an Image"),
12
+ outputs=gr.Textbox(label="Generated Caption"),
13
+ title="Image Caption Generator",
14
+ description="Upload an image to generate a caption using the BLIP model."
15
+ )
16
+ if __name__ == "__main__":
17
+ demo.launch(share=True)