capture-price / app.py
gri11's picture
Update app.py
fee9141
# 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()