Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# %% [code] {"execution":{"iopub.status.busy":"2023-07-31T16:51:35.137587Z","iopub.execute_input":"2023-07-31T16:51:35.137972Z","iopub.status.idle":"2023-07-31T16:51:49.983937Z","shell.execute_reply.started":"2023-07-31T16:51:35.137942Z","shell.execute_reply":"2023-07-31T16:51:49.982981Z"}}
|
2 |
+
# This Python 3 environment comes with many helpful analytics libraries installed
|
3 |
+
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
|
4 |
+
# For example, here's several helpful packages to load
|
5 |
+
|
6 |
+
!pip install gradio
|
7 |
+
|
8 |
+
import numpy as np # linear algebra
|
9 |
+
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
|
10 |
+
|
11 |
+
# Input data files are available in the read-only "../input/" directory
|
12 |
+
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
|
13 |
+
|
14 |
+
import os
|
15 |
+
for dirname, _, filenames in os.walk('/kaggle/input'):
|
16 |
+
for filename in filenames:
|
17 |
+
print(os.path.join(dirname, filename))
|
18 |
+
|
19 |
+
# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All"
|
20 |
+
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
|
21 |
+
|
22 |
+
# %% [code] {"execution":{"iopub.status.busy":"2023-07-31T16:52:23.519405Z","iopub.execute_input":"2023-07-31T16:52:23.519821Z","iopub.status.idle":"2023-07-31T16:52:30.470389Z","shell.execute_reply.started":"2023-07-31T16:52:23.519792Z","shell.execute_reply":"2023-07-31T16:52:30.469705Z"}}
|
23 |
+
import gradio as gr
|
24 |
+
from fastai.vision.all import *
|
25 |
+
import skimage
|
26 |
+
|
27 |
+
learn = load_learner('/kaggle/input/bicycle-model/model.pkl')
|
28 |
+
|
29 |
+
# %% [code] {"execution":{"iopub.status.busy":"2023-07-31T16:52:36.499387Z","iopub.execute_input":"2023-07-31T16:52:36.499737Z","iopub.status.idle":"2023-07-31T16:52:36.506774Z","shell.execute_reply.started":"2023-07-31T16:52:36.499713Z","shell.execute_reply":"2023-07-31T16:52:36.505348Z"}}
|
30 |
+
labels = learn.dls.vocab
|
31 |
+
|
32 |
+
def predict(img):
|
33 |
+
img = PILImage.create(img)
|
34 |
+
pred, idx, probs = learn.predict(img)
|
35 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
36 |
+
|
37 |
+
# %% [code] {"execution":{"iopub.status.busy":"2023-07-31T17:01:15.166908Z","iopub.execute_input":"2023-07-31T17:01:15.168263Z","iopub.status.idle":"2023-07-31T17:01:25.050227Z","shell.execute_reply.started":"2023-07-31T17:01:15.168215Z","shell.execute_reply":"2023-07-31T17:01:25.049147Z"}}
|
38 |
+
examples = ['/kaggle/input/examples/street_bicycle.jpg',
|
39 |
+
'/kaggle/input/examples/street_image.jpg']
|
40 |
+
|
41 |
+
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)),
|
42 |
+
title = "bicycle detector",
|
43 |
+
examples = examples,
|
44 |
+
interpretation = 'default',
|
45 |
+
enable_queue = True,
|
46 |
+
outputs = gr.outputs.Label(num_top_classes=3)).launch(share=True),
|