Dileep7729 commited on
Commit
1d68216
1 Parent(s): a1e4e08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -9,13 +9,16 @@ model = BlipForConditionalGeneration.from_pretrained("quadranttechnologies/Dilee
9
 
10
  # Define a function to generate captions for the uploaded image
11
  def generate_caption(image):
12
- # Convert the image into the required format for the model
13
- inputs = processor(image, return_tensors="pt")
 
14
 
15
- # Generate caption
16
- outputs = model.generate(**inputs)
17
- caption = processor.decode(outputs[0], skip_special_tokens=True)
18
- return caption
 
 
19
 
20
  # Set up Gradio interface for image upload and caption generation
21
  interface = gr.Interface(
@@ -28,4 +31,5 @@ interface = gr.Interface(
28
 
29
  # Launch the Gradio app
30
  if __name__ == "__main__":
31
- interface.launch()
 
 
9
 
10
  # Define a function to generate captions for the uploaded image
11
  def generate_caption(image):
12
+ try:
13
+ # Convert the image into the required format for the model
14
+ inputs = processor(image, return_tensors="pt")
15
 
16
+ # Generate caption
17
+ outputs = model.generate(**inputs)
18
+ caption = processor.decode(outputs[0], skip_special_tokens=True)
19
+ return caption
20
+ except Exception as e:
21
+ return f"Error generating caption: {e}"
22
 
23
  # Set up Gradio interface for image upload and caption generation
24
  interface = gr.Interface(
 
31
 
32
  # Launch the Gradio app
33
  if __name__ == "__main__":
34
+ interface.launch(share=True) # Set share=True to enable public link if needed
35
+