suhail0318 commited on
Commit
fcd2cbc
·
verified ·
1 Parent(s): dbe92ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -21,20 +21,26 @@ def generate_caption(image):
21
  if any(keyword in caption.lower() for keyword in dal_keywords):
22
  return f"The image is related to dal"
23
  else:
24
- return ("This image is not related to dal")
25
 
26
  # Define the function for the Gradio interface
27
  def captioning_interface(image):
28
- return generate_caption(image)
 
 
 
 
 
29
 
30
  # Create the Gradio interface
31
  interface = gr.Interface(
32
  fn=captioning_interface,
33
- inputs=gr.Image(type="pil"),
34
- outputs=gr.Textbox(),
35
  title="Dal Detection",
36
- description="Upload an image to get a textual description. Only images related to dal (lentil) will be accepted."
 
37
  )
38
 
39
  # Launch the interface
40
- interface.launch(share=True)
 
21
  if any(keyword in caption.lower() for keyword in dal_keywords):
22
  return f"The image is related to dal"
23
  else:
24
+ return None # Return None if the image is not related to dal
25
 
26
  # Define the function for the Gradio interface
27
  def captioning_interface(image):
28
+ # Generate caption and check if related to dal
29
+ result = generate_caption(image)
30
+ if result:
31
+ return image, result # If related to dal, show the image and the message
32
+ else:
33
+ raise gr.Error("This image is not related to dal. Please upload an image related to dal.") # Trigger error
34
 
35
  # Create the Gradio interface
36
  interface = gr.Interface(
37
  fn=captioning_interface,
38
+ inputs=gr.Image(type="pil", label="Upload Image", image_mode='RGB'), # Removed the 'tool' argument
39
+ outputs=[gr.Image(type="pil", label="Image Preview"), gr.Textbox(label="Description")], # Show image only if related to dal
40
  title="Dal Detection",
41
+ description="Upload an image to get a textual description. Only images related to dal (lentil) will be accepted.",
42
+ allow_flagging="never" # Disable flagging for rejected images
43
  )
44
 
45
  # Launch the interface
46
+ interface.launch(share=True)