LEGENDCODER1 commited on
Commit
04a150f
·
verified ·
1 Parent(s): afff4a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -1,26 +1,26 @@
1
- # Import necessary libraries
2
  from transformers import pipeline
3
  import gradio as gr
4
 
5
- # Load a lightweight image classification model
6
- model = pipeline("image-classification", model="facebook/deit-tiny-patch16-224", cache_dir="./model_cache")
7
 
8
- # Function to classify an uploaded image
9
  def classify_image(image):
10
- predictions = model(image) # Make predictions
11
- # Format predictions as a dictionary: Label -> Confidence
12
  return {pred["label"]: round(pred["score"], 4) for pred in predictions}
13
 
14
- # Create a Gradio interface for the app
15
  interface = gr.Interface(
16
- fn=classify_image, # Function to call
17
- inputs=gr.Image(type="pil"), # Input: Image (PIL format)
18
- outputs=gr.Label(), # Output: Label with confidence scores
19
- title="Image Classification App",
20
- description="Upload an image, and the app will classify it using a vision transformer model."
21
  )
22
 
23
- # Run the app
24
  if __name__ == "__main__":
25
  interface.launch()
26
 
 
 
 
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
+ # Load a lightweight pre-trained model without specifying cache_dir
5
+ model = pipeline("image-classification", model="facebook/deit-tiny-patch16-224")
6
 
7
+ # Function to classify an image
8
  def classify_image(image):
9
+ predictions = model(image)
10
+ # Format predictions as {label: confidence}
11
  return {pred["label"]: round(pred["score"], 4) for pred in predictions}
12
 
13
+ # Gradio interface
14
  interface = gr.Interface(
15
+ fn=classify_image,
16
+ inputs=gr.Image(type="pil"),
17
+ outputs=gr.Label(),
18
+ title="Image Classifier Test",
19
+ description="Upload an image to classify."
20
  )
21
 
22
+ # Launch the app
23
  if __name__ == "__main__":
24
  interface.launch()
25
 
26
+