SivaResearch commited on
Commit
3d276f5
1 Parent(s): 22cbf4e

Added Gradio app for all opensource classifier battle

Browse files
Files changed (1) hide show
  1. app.ipynb +0 -110
app.ipynb DELETED
@@ -1,110 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": 1,
6
- "metadata": {},
7
- "outputs": [
8
- {
9
- "name": "stderr",
10
- "output_type": "stream",
11
- "text": [
12
- "c:\\Users\\iitsi\\anaconda3\\lib\\site-packages\\gradio\\blocks.py:503: UserWarning: Cannot load huggingface. Caught Exception: The space huggingface does not exist\n",
13
- " warnings.warn(f\"Cannot load {theme}. Caught Exception: {str(e)}\")\n",
14
- "c:\\Users\\iitsi\\anaconda3\\lib\\site-packages\\gradio\\deprecation.py:40: UserWarning: `layout` parameter is deprecated, and it has no effect\n",
15
- " warnings.warn(value)\n",
16
- "ERROR: [Errno 10048] error while attempting to bind on address ('127.0.0.1', 7864): only one usage of each socket address (protocol/network address/port) is normally permitted\n"
17
- ]
18
- }
19
- ],
20
- "source": [
21
- "import gradio as gr\n",
22
- "from transformers import pipeline\n",
23
- "\n",
24
- "model_names = [\n",
25
- " \"apple/mobilevit-small\",\n",
26
- " \"facebook/deit-base-patch16-224\",\n",
27
- " \"facebook/convnext-base-224\",\n",
28
- " \"google/vit-base-patch16-224\",\n",
29
- " \"google/mobilenet_v2_1.4_224\",\n",
30
- " \"microsoft/resnet-50\",\n",
31
- " \"microsoft/swin-base-patch4-window7-224\",\n",
32
- " \"microsoft/beit-base-patch16-224\",\n",
33
- " \"nvidia/mit-b0\",\n",
34
- " \"shi-labs/nat-base-in1k-224\",\n",
35
- " \"shi-labs/dinat-base-in1k-224\",\n",
36
- "]\n",
37
- "\n",
38
- "\n",
39
- "def process(image_file, top_k):\n",
40
- " labels = []\n",
41
- " for m in model_names:\n",
42
- " p = pipeline(\"image-classification\", model=m)\n",
43
- " pred = p(image_file)\n",
44
- " labels.append({x[\"label\"]: x[\"score\"] for x in pred[:top_k]})\n",
45
- " return labels\n",
46
- "\n",
47
- "\n",
48
- "# Inputs\n",
49
- "image = gr.Image(type=\"filepath\", label=\"Upload an image\")\n",
50
- "top_k = gr.Slider(minimum=1, maximum=5, step=1, value=5, label=\"Top k classes\")\n",
51
- "\n",
52
- "# Output\n",
53
- "labels = [gr.Label(label=m) for m in model_names]\n",
54
- "\n",
55
- "description = \"This Space lets you quickly compare the most popular image classifiers available on the hub, including the recent NAT and DINAT models. All of them have been fine-tuned on the ImageNet-1k dataset. Anecdotally, the three sample images have been generated with a Stable Diffusion model :)\"\n",
56
- "\n",
57
- "iface = gr.Interface(\n",
58
- " theme=\"huggingface\",\n",
59
- " description=description,\n",
60
- " layout=\"horizontal\",\n",
61
- " fn=process,\n",
62
- " inputs=[image, top_k],\n",
63
- " outputs=labels,\n",
64
- " examples=[\n",
65
- " [\"bike.jpg\", 5],\n",
66
- " [\"car.jpg\", 5],\n",
67
- " [\"food.jpg\", 5],\n",
68
- " ],\n",
69
- " allow_flagging=\"never\",\n",
70
- ")\n",
71
- "\n",
72
- "iface.launch()\n"
73
- ]
74
- },
75
- {
76
- "cell_type": "code",
77
- "execution_count": null,
78
- "metadata": {},
79
- "outputs": [],
80
- "source": []
81
- }
82
- ],
83
- "metadata": {
84
- "kernelspec": {
85
- "display_name": "base",
86
- "language": "python",
87
- "name": "python3"
88
- },
89
- "language_info": {
90
- "codemirror_mode": {
91
- "name": "ipython",
92
- "version": 3
93
- },
94
- "file_extension": ".py",
95
- "mimetype": "text/x-python",
96
- "name": "python",
97
- "nbconvert_exporter": "python",
98
- "pygments_lexer": "ipython3",
99
- "version": "3.9.13"
100
- },
101
- "orig_nbformat": 4,
102
- "vscode": {
103
- "interpreter": {
104
- "hash": "a10896378c7586fe060a2352f1f55c7416a5095f8b10e25e98ff567d7ae9c79d"
105
- }
106
- }
107
- },
108
- "nbformat": 4,
109
- "nbformat_minor": 2
110
- }