Sagar Thacker commited on
Commit
925325b
·
1 Parent(s): 6dd5319

Updated app.py and added examples

Browse files
Files changed (6) hide show
  1. .gitattributes +4 -0
  2. app.py +43 -32
  3. examples/basset.jpg +3 -0
  4. examples/cat.jpg +3 -0
  5. examples/dog.jpg +3 -0
  6. examples/dunno.jpg +3 -0
.gitattributes CHANGED
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ examples/basset.jpg filter=lfs diff=lfs merge=lfs -text
37
+ examples/cat.jpg filter=lfs diff=lfs merge=lfs -text
38
+ examples/dog.jpg filter=lfs diff=lfs merge=lfs -text
39
+ examples/dunno.jpg filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -27,37 +27,47 @@ def predict(pickup, dropoff, trip_distance):
27
  return "The predicted duration is %.4f minutes." % duration
28
 
29
  with gr.Blocks() as demo:
30
- gr.Markdown("Predict Taxi Duration or Classify dog breeds using this demo")
 
 
 
 
 
 
31
 
32
  with gr.Tab("Predict Taxi Duration"):
33
  with gr.Row():
34
- pickup = gr.Dropdown(
35
- choices=list(zone_lookup["borough_zone"]),
36
- label="Pickup Location",
37
- info="The location where the passenger(s) were picked up",
38
- value=lambda: random.choice(zone_lookup["borough_zone"])
39
- )
40
-
41
- dropoff = gr.Dropdown(
42
- choices=list(zone_lookup["borough_zone"]),
43
- label="Dropoff Location",
44
- info="The location where the passenger(s) were dropped off",
45
- value=lambda: random.choice(zone_lookup["borough_zone"])
46
- )
47
-
48
- trip_distance = gr.Slider(
49
- minimum=0.0,
50
- maximum=100.0,
51
- step=0.1,
52
- label="Trip Distance",
53
- info="The trip distance in miles calculated by the taximeter",
54
- value=lambda: random.uniform(0.0, 100.0)
55
- )
56
- with gr.Column():
57
- output = gr.Textbox(label="Output Box")
58
- predict_btn = gr.Button("Predict")
 
 
 
 
59
 
60
- with gr.Tab("Classify Dog Breed"):
61
  def is_cat(x): return x[0].isupper()
62
 
63
  learn = load_learner('./models/model.pkl')
@@ -68,14 +78,15 @@ with gr.Blocks() as demo:
68
  pred, idx, probs = learn.predict(img)
69
  return dict(zip(categories, map(float,probs)))
70
 
71
- image = gr.inputs.Image(shape=(192, 192))
72
- label = gr.outputs.Label()
73
- examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
 
 
74
 
75
  classify_btn = gr.Button("Predict")
76
 
77
-
78
  predict_btn.click(fn=predict, inputs=[pickup, dropoff, trip_distance], outputs=output, api_name="predict-duration")
79
  classify_btn.click(fn=classify_image, inputs=image, outputs=label, api_name="classify-dog-breed")
80
 
81
- demo.launch()
 
27
  return "The predicted duration is %.4f minutes." % duration
28
 
29
  with gr.Blocks() as demo:
30
+ gr.Markdown("""
31
+ This demo is a simple example of how to use Gradio to create a web interface for your machine learning models.
32
+
33
+ Models used in this demo are very simple and are not meant to perform well. The goal is to show how to use Gradio with a simple model.
34
+ """)
35
+
36
+ gr.Markdown("Predict Taxi Duration or Classify dog vs cat using this demo")
37
 
38
  with gr.Tab("Predict Taxi Duration"):
39
  with gr.Row():
40
+ with gr.Column():
41
+ with gr.Row():
42
+ pickup = gr.Dropdown(
43
+ choices=list(zone_lookup["borough_zone"]),
44
+ label="Pickup Location",
45
+ info="The location where the passenger(s) were picked up",
46
+ value=lambda: random.choice(zone_lookup["borough_zone"])
47
+ )
48
+
49
+ dropoff = gr.Dropdown(
50
+ choices=list(zone_lookup["borough_zone"]),
51
+ label="Dropoff Location",
52
+ info="The location where the passenger(s) were dropped off",
53
+ value=lambda: random.choice(zone_lookup["borough_zone"])
54
+ )
55
+
56
+ trip_distance = gr.Slider(
57
+ minimum=0.0,
58
+ maximum=100.0,
59
+ step=0.1,
60
+ label="Trip Distance",
61
+ info="The trip distance in miles calculated by the taximeter",
62
+ value=lambda: random.uniform(0.0, 100.0)
63
+ )
64
+ with gr.Column():
65
+ output = gr.Textbox(label="Output Box")
66
+ predict_btn = gr.Button("Predict")
67
+
68
+ examples = gr.Examples([["Queens - Bellerose", "Bronx - Schuylerville/Edgewater Park", 25], ["Bronx - Norwood", "rooklyn - Sunset Park West", 55]], inputs=[pickup, dropoff, trip_distance])
69
 
70
+ with gr.Tab("Classify Dog vs Cat"):
71
  def is_cat(x): return x[0].isupper()
72
 
73
  learn = load_learner('./models/model.pkl')
 
78
  pred, idx, probs = learn.predict(img)
79
  return dict(zip(categories, map(float,probs)))
80
 
81
+ with gr.Row():
82
+ image = gr.inputs.Image(shape=(192, 192))
83
+ label = gr.outputs.Label()
84
+
85
+ examples = gr.Examples(['./examples/dog.jpg', './examples/cat.jpg', './examples/dunno.jpg', './examples/basset.jpg'], inputs=[image])
86
 
87
  classify_btn = gr.Button("Predict")
88
 
 
89
  predict_btn.click(fn=predict, inputs=[pickup, dropoff, trip_distance], outputs=output, api_name="predict-duration")
90
  classify_btn.click(fn=classify_image, inputs=image, outputs=label, api_name="classify-dog-breed")
91
 
92
+ demo.launch(share=True)
examples/basset.jpg ADDED

Git LFS Details

  • SHA256: d4cb7457aedd287819ba4da40fd0adbac9447c09eb3b33416f9a1594c21126b1
  • Pointer size: 130 Bytes
  • Size of remote file: 74.8 kB
examples/cat.jpg ADDED

Git LFS Details

  • SHA256: 834d194a5414c079992879b92b780d02ca74737f07e59af475a0f70b1996249e
  • Pointer size: 132 Bytes
  • Size of remote file: 1.14 MB
examples/dog.jpg ADDED

Git LFS Details

  • SHA256: 985c78acad60e4f5636d988cf581dd457ca47ba4fc9b25a18582cd48f200af40
  • Pointer size: 130 Bytes
  • Size of remote file: 30.3 kB
examples/dunno.jpg ADDED

Git LFS Details

  • SHA256: 2f8f512709d13d53e3e27d26cf869e771c7c2f8e168a75819705095f63da1d3e
  • Pointer size: 130 Bytes
  • Size of remote file: 89.6 kB