Dharini Baskaran commited on
Commit
5071c90
·
1 Parent(s): 4bb5406
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -47,6 +47,14 @@ def clear_outputs_on_upload(uploaded_file_path):
47
  return None, None, None, None, None
48
  return gr.update(value=uploaded_file_path), None, None, None, None
49
 
 
 
 
 
 
 
 
 
50
  def predict(uploaded_file_path):
51
  if uploaded_file_path is None:
52
  return None, None, "No file uploaded.", None
@@ -104,11 +112,14 @@ with gr.Blocks() as demo:
104
  error_output = gr.Textbox(label="Error Message", visible=False)
105
 
106
  uploaded_file.change(
107
- clear_outputs_on_upload,
108
- inputs=[uploaded_file],
109
- outputs=[uploaded_file, output_image, output_json, download_button, uploaded_image_display]
110
- )
111
-
 
 
 
112
  run_button.click(
113
  lambda x: (x, gr.update(interactive=False)),
114
  inputs=[uploaded_file],
 
47
  return None, None, None, None, None
48
  return gr.update(value=uploaded_file_path), None, None, None, None
49
 
50
+ def show_uploaded_image(path):
51
+ if path is None:
52
+ return None
53
+ try:
54
+ return Image.open(path)
55
+ except:
56
+ return None
57
+
58
  def predict(uploaded_file_path):
59
  if uploaded_file_path is None:
60
  return None, None, "No file uploaded.", None
 
112
  error_output = gr.Textbox(label="Error Message", visible=False)
113
 
114
  uploaded_file.change(
115
+ lambda path: (
116
+ gr.update(value=path),
117
+ None, None, None, show_uploaded_image(path)
118
+ ),
119
+ inputs=[uploaded_file],
120
+ outputs=[uploaded_file, output_image, output_json, download_button, uploaded_image_display]
121
+ )
122
+
123
  run_button.click(
124
  lambda x: (x, gr.update(interactive=False)),
125
  inputs=[uploaded_file],