Atul1997 commited on
Commit
dae61a5
·
verified ·
1 Parent(s): 97b1a05

Upload 9 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,10 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ animal_images/cat.png filter=lfs diff=lfs merge=lfs -text
37
+ animal_images/frog.png filter=lfs diff=lfs merge=lfs -text
38
+ animal_images/hippo.png filter=lfs diff=lfs merge=lfs -text
39
+ animal_images/jaguar.png filter=lfs diff=lfs merge=lfs -text
40
+ animal_images/sloth.png filter=lfs diff=lfs merge=lfs -text
41
+ animal_images/toucan.png filter=lfs diff=lfs merge=lfs -text
42
+ animal_images/turtle.png filter=lfs diff=lfs merge=lfs -text
animal_images/cat.png ADDED

Git LFS Details

  • SHA256: 8dbe0fc8a74b0c8d146ec75f337713082fdc40ac2c43e986fa0c8c8f2ff14d80
  • Pointer size: 131 Bytes
  • Size of remote file: 139 kB
animal_images/frog.png ADDED

Git LFS Details

  • SHA256: cf168ff5d42d4659ee810c4be7da623969106f4eecf0438ce8ad0104955ce20e
  • Pointer size: 131 Bytes
  • Size of remote file: 314 kB
animal_images/hippo.png ADDED

Git LFS Details

  • SHA256: a1085c6fbec1b0378e500d603c07670402c9c875827ceda32fb85305f3cc41ef
  • Pointer size: 131 Bytes
  • Size of remote file: 552 kB
animal_images/jaguar.png ADDED

Git LFS Details

  • SHA256: 086fe443bdbc479ff3d380f5a3ec2d348158bebb83a33f43263c3eaad593b33b
  • Pointer size: 131 Bytes
  • Size of remote file: 578 kB
animal_images/sloth.png ADDED

Git LFS Details

  • SHA256: 69f7720ee894a7472eb1c65f07726be7d2f1c293fed0b702e0d8b2b4363d78cd
  • Pointer size: 131 Bytes
  • Size of remote file: 414 kB
animal_images/toucan.png ADDED

Git LFS Details

  • SHA256: fe3ad6b6c8a78bd2e2c563002a251fbd1ce74e6728c201e4654e582d0dbed893
  • Pointer size: 131 Bytes
  • Size of remote file: 112 kB
animal_images/turtle.png ADDED

Git LFS Details

  • SHA256: 672334ae4126ea106db7c1a5850b68bee39d5d13badfea909a2c421639d767c6
  • Pointer size: 131 Bytes
  • Size of remote file: 426 kB
app.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Thu Jan 29 11:12:02 2026
5
+
6
+ @author: atulkar
7
+ """
8
+
9
+ import os
10
+ import gradio as gr
11
+ from transformers import pipeline
12
+
13
+ # -----------------------------
14
+ # Load Image Classification pipeline (pretrained)
15
+ # -----------------------------
16
+ # Good general-purpose ImageNet-style classifier
17
+ clf = pipeline(
18
+ task="image-classification",
19
+ model="google/vit-base-patch16-224"
20
+ )
21
+
22
+ # -----------------------------
23
+ # Locate example images (works locally + on HF Spaces)
24
+ # -----------------------------
25
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
26
+ EXAMPLES_DIR = os.path.join(BASE_DIR, "animal_images")
27
+
28
+ EXAMPLE_FILES = [
29
+ "cat.png",
30
+ "frog.png",
31
+ "hippo.png",
32
+ "jaguar.png",
33
+ "sloth.png",
34
+ "toucan.png",
35
+ "turtle.png",
36
+ ]
37
+
38
+ examples = []
39
+ missing = []
40
+ for fname in EXAMPLE_FILES:
41
+ fpath = os.path.join(EXAMPLES_DIR, fname)
42
+ if os.path.exists(fpath):
43
+ examples.append([fpath])
44
+ else:
45
+ missing.append(fname)
46
+
47
+ # -----------------------------
48
+ # Prediction function
49
+ # -----------------------------
50
+ def classify_image(img):
51
+ """
52
+ img comes in as a PIL image (because gr.Image(type="pil"))
53
+ Returns a dict for gr.Label: {label: confidence}
54
+ """
55
+ if img is None:
56
+ return {}
57
+
58
+ preds = clf(img, top_k=3)
59
+ return {p["label"]: float(p["score"]) for p in preds}
60
+
61
+
62
+ # -----------------------------
63
+ # Build Gradio App
64
+ # -----------------------------
65
+ with gr.Blocks(title="Animal Image Classifier") as demo:
66
+ gr.Markdown("# Animal Image Classifier")
67
+ gr.Markdown(
68
+ "Upload an animal image (or click an example). "
69
+ "This app uses a Hugging Face `image-classification` pipeline."
70
+ )
71
+
72
+ with gr.Row():
73
+ with gr.Column(scale=1):
74
+ inp = gr.Image(type="pil", label="Input Image")
75
+ with gr.Row():
76
+ btn = gr.Button("Submit", variant="primary")
77
+ clr = gr.Button("Clear")
78
+ with gr.Column(scale=1):
79
+ out = gr.Label(num_top_classes=3, label="Top Predictions")
80
+
81
+ btn.click(fn=classify_image, inputs=inp, outputs=out)
82
+ clr.click(fn=lambda: (None, {}), inputs=None, outputs=[inp, out])
83
+
84
+ if examples:
85
+ gr.Examples(
86
+ examples=examples,
87
+ inputs=inp,
88
+ label="Examples (from ./animal_images/)",
89
+ )
90
+
91
+ if missing:
92
+ gr.Markdown(
93
+ "\n\nMake sure the folder is next to `app.py` locally, "
94
+ "and uploaded into your Hugging Face Space repo when deploying."
95
+ )
96
+
97
+ # -----------------------------
98
+ # Launch
99
+ # -----------------------------
100
+ if __name__ == "__main__":
101
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch
4
+ pillow