Parthjain9925 commited on
Commit
13746d7
·
1 Parent(s): dbf39a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -1
app.py CHANGED
@@ -123,6 +123,58 @@ def predict_upload(image):
123
  k=show("geeks.jpg")
124
  return k
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  with gr.Blocks(title="Digit Recognizer") as demo:
127
  gr.Markdown("Flip text or image files using this demo.")
128
  with gr.Tabs():
@@ -139,4 +191,5 @@ with gr.Blocks(title="Digit Recognizer") as demo:
139
  image_button.click(predict_upload,image_input, image_output)
140
  text_button.click(predict_sketch,text_input,outputs=text_output)
141
 
142
- demo.launch(debug=True)
 
 
123
  k=show("geeks.jpg")
124
  return k
125
 
126
+ import numpy as np
127
+ import gradio as gr
128
+
129
+ def predict_sketch(img):
130
+ img_3d=img.reshape(-1,28,28,1)
131
+ im_resize=img_3d/255.0
132
+ prediction=nn.predict(im_resize).tolist()[0]
133
+ return {str(i):prediction[i] for i in range(10)}
134
+
135
+ def predict_upload(image):
136
+ im1 = image.save("/content/geeks.jpg")
137
+ k=show("/content/geeks.jpg")
138
+ return k
139
+
140
+ description='''
141
+ <h1>Digit Recognizer</h4>
142
+ <h2>You have Two options either you can draw the digit in the sketchpad or you can upload the image and see the results</h2>
143
+ '''
144
+
145
+ des2="Note:Draw Digits from 0-9 and Try to Draw the Digit in the center for better accuracy"
146
+
147
+ with gr.Blocks() as demo:
148
+
149
+ gr.Markdown(description)
150
+ with gr.Tabs():
151
+ with gr.TabItem("Sketch"):
152
+ gr.Markdown(des2)
153
+ with gr.Row():
154
+ text_input = gr.Sketchpad()
155
+ text_output = gr.Label(num_top_classes=3)
156
+ clr = gr.Button("Submit")
157
+
158
+ with gr.TabItem("Upload Image"):
159
+ with gr.Row():
160
+ image_input = gr.Image(type="pil",)
161
+ image_output = gr.Image(type="pil",)
162
+ image_button = gr.Button("Submit")
163
+ examples=["/content/tt.jpg","/content/multitest.jpg"]
164
+ gr.Examples(examples=examples,
165
+ inputs=image_input,
166
+ fn=predict_upload,
167
+ outputs=image_output)
168
+
169
+
170
+ image_input.change(predict_upload,image_input, image_output,examples)
171
+ text_input.change(predict_sketch,text_input,outputs=text_output)
172
+
173
+
174
+ demo.launch(debug=True)
175
+
176
+
177
+ '''
178
  with gr.Blocks(title="Digit Recognizer") as demo:
179
  gr.Markdown("Flip text or image files using this demo.")
180
  with gr.Tabs():
 
191
  image_button.click(predict_upload,image_input, image_output)
192
  text_button.click(predict_sketch,text_input,outputs=text_output)
193
 
194
+ demo.launch(debug=True)
195
+ '''