Okkoman commited on
Commit
33e8ffe
·
verified ·
1 Parent(s): b984328

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -1,14 +1,11 @@
1
- # AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
2
-
3
- # %% auto 0
4
  __all__ = ['modelname', 'pokemon_types', 'pokemon_types_en', 'examplespath', 'learn_inf', 'lang', 'prob_threshold',
5
  'classify_image']
6
 
7
  # %% ../app.ipynb 3
8
  import pandas as pd
9
 
10
- modelname = f'model_gen0.pkl'
11
- pokemon_types = pd.read_csv(f'pokemon.csv')
12
  pokemon_types_en = pokemon_types['en']
13
 
14
  examplespath = 'images/'
@@ -40,7 +37,7 @@ else:
40
  unknown = 'unknown'
41
 
42
  def classify_image(img):
43
- pred,pred_idx,probs = learn_inf.predict(img)
44
  index = pokemon_types_en[pokemon_types_en == pred].index[0]
45
  label = pokemon_types[lang].iloc[index]
46
  if probs[pred_idx] > prob_threshold:
@@ -55,12 +52,14 @@ with gr.Blocks() as demo:
55
  with gr.Row():
56
  gr.Markdown(description)
57
  with gr.Row():
58
- interf = gr.Interface(
59
- fn=classify_image,
60
- inputs=gr.inputs.Image(shape=(192,192)),
61
- outputs=gr.outputs.Label(),
62
- examples=examplespath,
63
- allow_flagging='auto')
 
 
64
 
65
  demo.launch(inline=False)
66
 
 
 
 
 
1
  __all__ = ['modelname', 'pokemon_types', 'pokemon_types_en', 'examplespath', 'learn_inf', 'lang', 'prob_threshold',
2
  'classify_image']
3
 
4
  # %% ../app.ipynb 3
5
  import pandas as pd
6
 
7
+ modelname = 'model_gen0.pkl'
8
+ pokemon_types = pd.read_csv('pokemon.csv')
9
  pokemon_types_en = pokemon_types['en']
10
 
11
  examplespath = 'images/'
 
37
  unknown = 'unknown'
38
 
39
  def classify_image(img):
40
+ pred, pred_idx, probs = learn_inf.predict(img)
41
  index = pokemon_types_en[pokemon_types_en == pred].index[0]
42
  label = pokemon_types[lang].iloc[index]
43
  if probs[pred_idx] > prob_threshold:
 
52
  with gr.Row():
53
  gr.Markdown(description)
54
  with gr.Row():
55
+ image_input = gr.Image(label="Upload an image", shape=(192, 192))
56
+ label_output = gr.Label(label="Prediction")
57
+ submit_button = gr.Button("Classify")
58
+
59
+ with gr.Row():
60
+ gr.Examples(examples=examplespath, inputs=image_input)
61
+
62
+ submit_button.click(fn=classify_image, inputs=image_input, outputs=label_output)
63
 
64
  demo.launch(inline=False)
65