gri11 commited on
Commit
ef43caa
·
1 Parent(s): 5e4fb43
Files changed (1) hide show
  1. app.py +39 -2
app.py CHANGED
@@ -1,7 +1,44 @@
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['learn', 'prices', 'greet', 'classify_image']
5
+
6
+ # %% app.ipynb 5
7
+ from fastai.vision.all import *
8
  import gradio as gr
9
 
10
  def greet(name):
11
  return "Hello " + name + "!!"
12
 
13
+ def classify_image(img):
14
+ pred, idx, probs = learn.predict(img)
15
+ return {
16
+ price: str(prices[pred]) + ' baht (' + pred + ")",
17
+ label: dict(zip(learn.dls.vocab, map(float, probs))),
18
+ }
19
+
20
+ learn = load_learner(path + 'model.pkl')
21
+
22
+ prices = {
23
+ 'ฟอกกี้': 20,
24
+ 'ฝาชี': 30,
25
+ }
26
+
27
+
28
+ # %% app.ipynb 8
29
+ with gr.Blocks() as demo:
30
+ gr.Markdown("Use your camera or image to get price!!!")
31
+ with gr.Row():
32
+ with gr.Column():
33
+ image_input = gr.Image(source='webcam')
34
+ price_btn = gr.Button("PRICE")
35
+ image_input2 = gr.Image()
36
+ price_btn2 = gr.Button("PRICE")
37
+ with gr.Column():
38
+ price = gr.Textbox(label="ITEM PRICE")
39
+ label = gr.Label()
40
+
41
+ price_btn.click(classify_image, inputs=image_input, outputs=[price, label])
42
+ price_btn2.click(classify_image, inputs=image_input2, outputs=[price, label])
43
+
44
+ demo.launch(debug=True, share=True)