Dileep7729 commited on
Commit
1aaff03
·
verified ·
1 Parent(s): 790f088

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -18
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  from transformers import CLIPModel, CLIPProcessor
3
  from PIL import Image
4
- import requests
5
 
6
  # Step 1: Load Fine-Tuned Model from Hugging Face Model Hub
7
  model_name = "quadranttechnologies/retail-content-safety-clip-finetuned"
@@ -68,7 +67,6 @@ def classify_image(image):
68
  }
69
 
70
  except Exception as e:
71
- # Log and return detailed error messages
72
  print(f"Error during classification: {e}")
73
  return {"Error": str(e)}
74
 
@@ -76,27 +74,13 @@ def classify_image(image):
76
  iface = gr.Interface(
77
  fn=classify_image,
78
  inputs=gr.Image(type="pil"),
79
- outputs=gr.Label(label="Output"), # Display probabilities as progress bars
80
  title="Content Safety Classification",
81
  description="Upload an image to classify it as 'safe' or 'unsafe' with corresponding probabilities.",
82
  )
83
 
84
- # Step 4: Test Before Launch
85
  if __name__ == "__main__":
86
- print("Testing model locally with a sample image...")
87
- try:
88
- # Test with a sample image
89
- url = "https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png"
90
- test_image = Image.open(requests.get(url, stream=True).raw)
91
-
92
- # Run the classification function
93
- print("Running local test...")
94
- result = classify_image(test_image)
95
- print(f"Local Test Result: {result}")
96
- except Exception as e:
97
- print(f"Error during local test: {e}")
98
-
99
- # Launch Gradio Interface
100
  print("Launching the Gradio interface...")
101
  iface.launch()
102
 
@@ -128,5 +112,6 @@ if __name__ == "__main__":
128
 
129
 
130
 
 
131
 
132
 
 
1
  import gradio as gr
2
  from transformers import CLIPModel, CLIPProcessor
3
  from PIL import Image
 
4
 
5
  # Step 1: Load Fine-Tuned Model from Hugging Face Model Hub
6
  model_name = "quadranttechnologies/retail-content-safety-clip-finetuned"
 
67
  }
68
 
69
  except Exception as e:
 
70
  print(f"Error during classification: {e}")
71
  return {"Error": str(e)}
72
 
 
74
  iface = gr.Interface(
75
  fn=classify_image,
76
  inputs=gr.Image(type="pil"),
77
+ outputs=gr.Textbox(label="Output (Debug Mode)"), # Use Textbox to display errors if any occur
78
  title="Content Safety Classification",
79
  description="Upload an image to classify it as 'safe' or 'unsafe' with corresponding probabilities.",
80
  )
81
 
82
+ # Step 4: Launch Gradio Interface
83
  if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  print("Launching the Gradio interface...")
85
  iface.launch()
86
 
 
112
 
113
 
114
 
115
+
116
 
117