notrey commited on
Commit
f172fcc
·
1 Parent(s): 173f5a2

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +27 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import BlipProcessor, BlipForConditionalGeneration
3
+ from PIL import Image
4
+
5
+ # Load an advanced image captioning model
6
+ processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
7
+ model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
8
+
9
+ # Function to generate a descriptive caption
10
+ def generate_caption(image):
11
+ inputs = processor(image, return_tensors="pt")
12
+ out = model.generate(**inputs, max_length=50, num_beams=5, repetition_penalty=1.5)
13
+ caption = processor.decode(out[0], skip_special_tokens=True)
14
+ return caption
15
+
16
+ # Gradio interface with webcam support
17
+ iface = gr.Interface(
18
+ fn=generate_caption,
19
+ inputs=[gr.Image(type="pil", source="webcam", label="Capture an image")],
20
+ outputs=gr.Textbox(label="Image Description"),
21
+ title="📷 Image Capture & Description App",
22
+ description="Capture an image using your webcam and let AI describe what's happening in the image!",
23
+ live=True,
24
+ )
25
+
26
+ if __name__ == "__main__":
27
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ transformers
3
+ gradio