sherab65 commited on
Commit
c15ebd3
·
verified ·
1 Parent(s): 4bdeb98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -31,31 +31,35 @@
31
  # # Launch the app
32
  # gradio_app.launch()
33
 
34
- classifier = pipeline("image-classification", model="sherab65/age-classification")
35
-
36
  import gradio as gr
37
  from PIL import Image
38
 
 
 
 
39
  # Prediction function
40
  def predict(input_img):
41
- # Get the predictions from the pipeline
42
  predictions = classifier(input_img)
43
 
 
44
  result = {p["label"]: p["score"] for p in predictions}
45
-
46
- # Return the image and the top predictions as a string
47
  top_labels = [f"{label}: {score:.2f}" for label, score in result.items()]
 
48
  return input_img, "\n".join(top_labels)
49
 
50
- # Create the Gradio interface
51
  gradio_app = gr.Interface(
52
  fn=predict,
53
- inputs=gr.Image(label="Select Image", sources=['upload', 'webcam'], type="pil"),
54
  outputs=[
55
- gr.Image(label="Processed Image"),
56
- gr.Textbox(label="Result", placeholder="Top predictions here")
57
  ],
58
- title="Age Classification",
 
59
  )
60
 
 
61
  gradio_app.launch()
 
 
31
  # # Launch the app
32
  # gradio_app.launch()
33
 
34
+ from transformers import pipeline
 
35
  import gradio as gr
36
  from PIL import Image
37
 
38
+ # Load the pretrained model pipeline
39
+ classifier = pipeline("image-classification", model="sherab65/age-classification")
40
+
41
  # Prediction function
42
  def predict(input_img):
 
43
  predictions = classifier(input_img)
44
 
45
+ # Format predictions
46
  result = {p["label"]: p["score"] for p in predictions}
 
 
47
  top_labels = [f"{label}: {score:.2f}" for label, score in result.items()]
48
+
49
  return input_img, "\n".join(top_labels)
50
 
51
+ # Create Gradio interface
52
  gradio_app = gr.Interface(
53
  fn=predict,
54
+ inputs=gr.Image(label="Select Image", sources=["upload", "webcam"], type="pil"),
55
  outputs=[
56
+ gr.Image(label="Uploaded Image"),
57
+ gr.Textbox(label="Predicted Age Group(s)")
58
  ],
59
+ title="Age Classification using Hugging Face Model",
60
+ description="Upload or capture an image to classify the person's age group."
61
  )
62
 
63
+ # Launch the app
64
  gradio_app.launch()
65
+