CalamityJon commited on
Commit
424fe21
·
verified ·
1 Parent(s): cc10ca9

Upload 9 files

Browse files
Files changed (10) hide show
  1. .gitattributes +7 -0
  2. animal_image_app.py +114 -0
  3. cat.png +3 -0
  4. frog.png +3 -0
  5. hippo.png +3 -0
  6. jaguar.png +3 -0
  7. requirements.txt +4 -0
  8. sloth.png +3 -0
  9. toucan.png +3 -0
  10. turtle.png +3 -0
.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
+ cat.png filter=lfs diff=lfs merge=lfs -text
37
+ frog.png filter=lfs diff=lfs merge=lfs -text
38
+ hippo.png filter=lfs diff=lfs merge=lfs -text
39
+ jaguar.png filter=lfs diff=lfs merge=lfs -text
40
+ sloth.png filter=lfs diff=lfs merge=lfs -text
41
+ toucan.png filter=lfs diff=lfs merge=lfs -text
42
+ turtle.png filter=lfs diff=lfs merge=lfs -text
animal_image_app.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from PIL import Image
4
+
5
+ # Load image classification model
6
+ # Using a pre-trained model that can classify various animals and objects
7
+ classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
8
+
9
+ def classify_image(image):
10
+ """
11
+ Classify an uploaded animal image and return top predictions with progress bars
12
+ """
13
+ if image is None:
14
+ return "<div style='font-family: Arial, sans-serif; padding: 20px; text-align: center; color: #666;'>Please upload an image.</div>"
15
+
16
+ # Classify the image
17
+ results = classifier(image)
18
+
19
+ # Format results with HTML progress bars - show top 5 predictions
20
+ html_results = "<div style='font-family: Arial, sans-serif;'>"
21
+ html_results += "<h3 style='margin-top: 0;'>Top Predictions:</h3>"
22
+
23
+ for i, result in enumerate(results[:5], 1):
24
+ label = result['label']
25
+ score = result['score'] * 100
26
+ score_int = int(score)
27
+
28
+ # Create progress bar with color gradient (green for high, yellow for medium, red for low)
29
+ if score_int >= 70:
30
+ bar_color = "#4CAF50" # Green
31
+ elif score_int >= 40:
32
+ bar_color = "#FF9800" # Orange
33
+ else:
34
+ bar_color = "#F44336" # Red
35
+
36
+ html_results += f"""
37
+ <div style='margin-bottom: 15px;'>
38
+ <div style='display: flex; justify-content: space-between; margin-bottom: 5px;'>
39
+ <span style='font-weight: bold;'>{i}. {label}</span>
40
+ <span style='font-weight: bold; color: #333;'>{score:.2f}%</span>
41
+ </div>
42
+ <div style='background-color: #e0e0e0; border-radius: 10px; height: 25px; overflow: hidden;'>
43
+ <div style='background-color: {bar_color}; height: 100%; width: {score:.2f}%; transition: width 0.3s ease; border-radius: 10px;'></div>
44
+ </div>
45
+ </div>
46
+ """
47
+
48
+ html_results += "</div>"
49
+ return html_results
50
+
51
+ # Create the Gradio interface
52
+ with gr.Blocks(title="Animal Image Classifier") as demo:
53
+ gr.Markdown("# Animal Image Classifier")
54
+ gr.Markdown("Upload an animal photo to classify it using AI!")
55
+
56
+ with gr.Row():
57
+ with gr.Column():
58
+ # Image input
59
+ input_image = gr.Image(
60
+ type="pil",
61
+ label="Upload Animal Photo"
62
+ )
63
+
64
+ # Classify button
65
+ classify_btn = gr.Button("Classify Image", variant="primary", size="lg")
66
+ clear_btn = gr.Button("Clear", variant="secondary")
67
+
68
+ with gr.Column():
69
+ # Output for classification results with HTML progress bars
70
+ output_html = gr.HTML(
71
+ label="Classification Results"
72
+ )
73
+
74
+ # Example images at the bottom
75
+ gr.Markdown("### Example Images")
76
+ gr.Markdown("Try these example images:")
77
+
78
+ example_images = [
79
+ "cat.png",
80
+ "frog.png",
81
+ "hippo.png",
82
+ "jaguar.png",
83
+ "sloth.png",
84
+ "toucan.png",
85
+ "turtle.png"
86
+ ]
87
+
88
+ # Create example gallery - images are in the same directory as this script
89
+ import os
90
+ script_dir = os.path.dirname(os.path.abspath(__file__))
91
+ example_paths = [[os.path.join(script_dir, img)] for img in example_images]
92
+
93
+ gr.Examples(
94
+ examples=example_paths,
95
+ inputs=input_image,
96
+ label="Click on an example image to load it"
97
+ )
98
+
99
+ # Define button actions
100
+ classify_btn.click(
101
+ fn=classify_image,
102
+ inputs=input_image,
103
+ outputs=output_html
104
+ )
105
+
106
+ clear_btn.click(
107
+ fn=lambda: (None, "<div></div>"),
108
+ inputs=None,
109
+ outputs=[input_image, output_html]
110
+ )
111
+
112
+ # Launch the app
113
+ if __name__ == "__main__":
114
+ demo.launch()
cat.png ADDED

Git LFS Details

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

Git LFS Details

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

Git LFS Details

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

Git LFS Details

  • SHA256: 086fe443bdbc479ff3d380f5a3ec2d348158bebb83a33f43263c3eaad593b33b
  • Pointer size: 131 Bytes
  • Size of remote file: 578 kB
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch
4
+ sentencepiece
sloth.png ADDED

Git LFS Details

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

Git LFS Details

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

Git LFS Details

  • SHA256: 672334ae4126ea106db7c1a5850b68bee39d5d13badfea909a2c421639d767c6
  • Pointer size: 131 Bytes
  • Size of remote file: 426 kB