Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
| 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 |
+
|