File size: 1,188 Bytes
ef43caa
 
 
976aa3b
ef43caa
 
976aa3b
 
da9fd8c
ef43caa
5e4fb43
 
 
 
 
ef43caa
 
 
fee9141
ef43caa
 
 
9ebfcec
ef43caa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bf82b0a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.

# %% auto 0
__all__ = ['learn', 'prices', 'greet', 'classify_image']

# %% app.ipynb 5
import os
os.system('pip install -Uqq fastai')

from fastai.vision.all import *
import gradio as gr

def greet(name):
    return "Hello " + name + "!!"

def classify_image(img):
  pred, idx, probs = learn.predict(img)
  return {
      price: str(prices[pred] if pred in prices else 0) + ' baht (' + pred + ")",
      label: dict(zip(learn.dls.vocab, map(float, probs))),
  }

learn = load_learner('model.pkl')

prices = {
    'ฟอกกี้': 20,
    'ฝาชี': 30,
}


# %% app.ipynb 8
with gr.Blocks() as demo:
  gr.Markdown("Use your camera or image to get price!!!")
  with gr.Row():
    with gr.Column():
      image_input = gr.Image(source='webcam')
      price_btn = gr.Button("PRICE")
      image_input2 = gr.Image()
      price_btn2 = gr.Button("PRICE")
    with gr.Column():
      price = gr.Textbox(label="ITEM PRICE")
      label = gr.Label()
      
  price_btn.click(classify_image, inputs=image_input, outputs=[price, label])
  price_btn2.click(classify_image, inputs=image_input2, outputs=[price, label])

demo.launch()