Beansbeansbeansbeans commited on
Commit
621b8c6
·
verified ·
1 Parent(s): 7295a09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -146
app.py CHANGED
@@ -1,10 +1,7 @@
1
- # from __future__ import annotations
2
  import gradio as gr
3
  from huggingface_hub import from_pretrained_fastai
4
  import os
5
- from typing import Iterable
6
- # from gradio.themes.base import Base
7
- # from gradio.themes.utils import colors, fonts, sizes
8
 
9
  os.environ["HF_ENDPOINT"] = "https://huggingface.co"
10
 
@@ -35,24 +32,6 @@ material_num_name_dict = {
35
  "others": "Others",
36
  }
37
 
38
- # No plastic bags, wrap, or film (please take back to a local retailer)
39
- # No Styrofoam
40
- # No single-use paper (no paper towels, napkins, tissues, or paper plates)
41
- # No clothing, shoes, or textiles (take gently used items to a donation center)
42
- # No chain, wire, hoses, or hangers of any kind
43
- # No lumber, scrap wood, or yard waste
44
- # No food or liquids
45
- # No soiled food boxes
46
- # No electronics
47
- # No furniture
48
-
49
- # Cardboard and boxboard (flatten boxes)
50
- # Paper: junk mail, magazines, newspaper (no napkins, tissues, paper towels, or paper plates)
51
- # Aluminum and steel cans (no scrap metal)
52
- # Plastic bottles, tubs, and jugs (no plastic bags, wrap, film, or Styrofoam)
53
- # Glass bottles and jars (remove all lids)
54
- # Poly-coated cartons
55
-
56
  plastic_item_num_dict = {
57
  "CD Disk": ["CD Disk", "No, find a local e-waste collection near you (refer to the info page!!!)"],
58
  "Straw": ["Straw", "No, dispose as general waste"],
@@ -94,66 +73,6 @@ paper_item_num_dict = {
94
  "Tissue Paper": ["Tissue Paper", "No, dispose as general waste"]
95
  }
96
 
97
- # class Seafoam(Base):
98
- # def __init__(
99
- # self,
100
- # *,
101
- # primary_hue: colors.Color | str = colors.emerald,
102
- # secondary_hue: colors.Color | str = colors.teal,
103
- # neutral_hue: colors.Color | str = colors.teal,
104
- # spacing_size: sizes.Size | str = sizes.spacing_md,
105
- # radius_size: sizes.Size | str = sizes.radius_md,
106
- # text_size: sizes.Size | str = sizes.text_lg,
107
- # font: fonts.Font
108
- # | str
109
- # | Iterable[fonts.Font | str] = (
110
- # fonts.GoogleFont("Quicksand"),
111
- # "ui-sans-serif",
112
- # "sans-serif",
113
- # ),
114
- # font_mono: fonts.Font
115
- # | str
116
- # | Iterable[fonts.Font | str] = (
117
- # fonts.GoogleFont("IBM Plex Mono"),
118
- # "ui-monospace",
119
- # "monospace",
120
- # ),
121
- # ):
122
- # super().__init__(
123
- # primary_hue=primary_hue,
124
- # secondary_hue=secondary_hue,
125
- # neutral_hue=neutral_hue,
126
- # spacing_size=spacing_size,
127
- # radius_size=radius_size,
128
- # text_size=text_size,
129
- # font=font,
130
- # font_mono=font_mono,
131
- # )
132
-
133
- # super().set(
134
- # body_background_fill="linear-gradient(45deg, *primary_200, *primary_200 10px, *primary_50 10px, *primary_50 20px)",
135
- # body_background_fill_dark="linear-gradient(45deg, *primary_200, *primary_200 10px, *primary_50 10px, *primary_50 20px)",
136
- # stat_background_fill_dark="linear-gradient(to right, *primary_400, *primary_200)",
137
- # error_background_fill_dark=f"linear-gradient(to right, {colors.red.c100}, *background_fill_secondary)",
138
- # button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)",
139
- # button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)",
140
- # button_primary_background_fill_hover_dark="linear-gradient(90deg, *primary_200, *secondary_300)",
141
- # button_primary_text_color="white",
142
- # button_primary_background_fill_dark="linear-gradient(90deg, *primary_300, *secondary_400)",
143
- # slider_color="*secondary_300",
144
- # slider_color_dark="*secondary_300",
145
- # block_title_text_weight="600",
146
- # block_border_width="3px",
147
- # block_shadow="*shadow_drop_lg",
148
- # button_shadow="*shadow_drop_lg",
149
- # button_large_padding="32px",
150
- # )
151
- # for k in list(self.__dict__.keys()):
152
- # if '_dark' in k:
153
- # setattr(self,k,None)
154
-
155
- # seafoam = Seafoam()
156
-
157
  def predict_image(inp):
158
  """
159
  Performs inference for a given input image and returns the prediction and CAM image.
@@ -201,68 +120,6 @@ def predict_image(inp):
201
  except:
202
  raise Exception("Invalid file format! Please only upload .jpg or .png files!")
203
 
204
-
205
- with gr.Blocks(title="Trash Classification", css="#custom_header {min-height: 3rem} #custom_title {min-height: 3rem; text-align: center}") as demo:#, theme=seafoam) as demo:
206
  gr.Markdown("# Check whether your trash is recyclable or not!", elem_id="custom_title")
207
- gr.Markdown("Gradio Inference interface for classification of trash and recyclables. To use it, simply upload your image, or click one of the examples to load them. Images uploaded are never saved or indexed. No data or images uploaded are saved or logged.", elem_id="custom_title")
208
-
209
- with gr.Column():
210
- with gr.Column():
211
- with gr.Group():
212
- gr.Markdown("## Inputs", elem_id="custom_header")
213
- input_image = gr.Image(label="Input Image")
214
- input_image.scale(height=240)
215
- btn = gr.Button(value="Submit")
216
- btn.scale(full_width=True)
217
- with gr.Column():
218
- with gr.Group():
219
- gr.Markdown("## Outputs", elem_id="custom_header")
220
- recycling_qn = gr.outputs.Textbox(label="Is this recyclable?")
221
- recycling_advice = gr.outputs.Textbox(label="It is not recyclable when:")
222
- with gr.Row():
223
- material_probs = gr.outputs.Label(label="Material Prediction")
224
- item_probs = gr.outputs.Label(label="Item Prediction")
225
-
226
- gr.Examples(
227
- examples=examples,
228
- inputs=input_image,
229
- fn=predict_image,
230
- cache_examples=False,
231
- )
232
-
233
- btn.click(predict_image, inputs=[input_image],
234
- outputs=[material_probs, item_probs, recycling_qn, recycling_advice])
235
-
236
- # css = """
237
- # #warning {background-color: #FFCCCB}
238
- # #custom_header {min-height: 3rem} #custom_title {min-height: 3rem; text-align: center}
239
- # .feedback textarea {font-size: 24px !important}
240
- # """
241
-
242
- # with gr.Blocks(title="Green Genius", css=css, theme=gr.themes.Monochrome()
243
- # ) as demo:
244
-
245
- # with gr.Column():
246
- # with gr.Column():
247
- # input_image = gr.Image(label="Input Image")
248
- # input_image.style(height=240)
249
- # btn = gr.Button(value="Submit")
250
- # btn.style(full_width=True)
251
- # with gr.Column():
252
- # gr.Markdown("# We think this is?",elem_id="custom_header")
253
- # with gr.Row():
254
- # item_probs = gr.outputs.Label(label=" ",num_top_classes=1)
255
- # material_probs = gr.outputs.Label(label=" ",num_top_classes=1)
256
- # gr.Markdown("# Can it Recycle?", elem_id="custom_header")
257
- # recycling_qn = gr.outputs.Label(label=" ",)
258
- # gr.Markdown("# This Cant be Recycled when: ",elem_id="custom_header")
259
- # recycling_advice = gr.outputs.Label(label=" ",)
260
-
261
-
262
-
263
-
264
- # btn.click(predict_image, inputs=[input_image],
265
- # outputs=[material_probs, item_probs, recycling_qn, recycling_advice])
266
-
267
- if __name__ == "__main__":
268
- demo.launch(show_error=True)
 
1
+ from __future__ import annotations
2
  import gradio as gr
3
  from huggingface_hub import from_pretrained_fastai
4
  import os
 
 
 
5
 
6
  os.environ["HF_ENDPOINT"] = "https://huggingface.co"
7
 
 
32
  "others": "Others",
33
  }
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  plastic_item_num_dict = {
36
  "CD Disk": ["CD Disk", "No, find a local e-waste collection near you (refer to the info page!!!)"],
37
  "Straw": ["Straw", "No, dispose as general waste"],
 
73
  "Tissue Paper": ["Tissue Paper", "No, dispose as general waste"]
74
  }
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  def predict_image(inp):
77
  """
78
  Performs inference for a given input image and returns the prediction and CAM image.
 
120
  except:
121
  raise Exception("Invalid file format! Please only upload .jpg or .png files!")
122
 
123
+ with gr.Blocks(title="Trash Classification") as demo:
 
124
  gr.Markdown("# Check whether your trash is recyclable or not!", elem_id="custom_title")
125
+ gr.Markdown("Gradio Inference interface for classification of trash and recyclables. To use it, simply upload your image, or click one of the examples to load them. Images uploaded are never saved or indexed. No data