fmussari commited on
Commit
1fabc95
1 Parent(s): 4e2ce6e
Files changed (1) hide show
  1. app.py +30 -26
app.py CHANGED
@@ -1,7 +1,7 @@
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: telecom_object_detection.ipynb.
2
 
3
  # %% auto 0
4
- __all__ = ['title', 'css', 'urls', 'demo', 'set_example_url', 'set_example_image']
5
 
6
  # %% telecom_object_detection.ipynb 2
7
  import gradio as gr
@@ -16,46 +16,50 @@ h1#title {
16
  }
17
  '''
18
 
19
- # %% telecom_object_detection.ipynb 8
20
- urls = ["https://c8.alamy.com/comp/J2AB4K/the-new-york-stock-exchange-on-the-wall-street-in-new-york-J2AB4K.jpg"]
 
21
 
22
- demo = gr.Blocks(css=css)
23
 
24
- def set_example_url(example: list) -> dict:
25
- return gr.Textbox.update(value=example[0])
26
 
27
- def set_example_image(example: list) -> dict:
28
- return gr.Image.update(value=example[0])
29
 
30
- with demo:
 
31
  gr.Markdown(title)
32
 
33
  with gr.Tabs():
34
-
35
- with gr.TabItem('Image Upload'):
36
  with gr.Row():
37
- img_input = gr.Image(type='pil')
38
- img_output_from_upload= gr.Image(shape=(650,650))
39
-
40
  with gr.Row():
41
- example_images = gr.Dataset(components=[img_input],
42
  samples=[[path.as_posix()] for path in sorted(Path('images').rglob('*.jpg'))]
 
 
 
 
43
  )
44
- img_but = gr.Button('Detect')
45
-
46
- with gr.TabItem('Image URL'):
 
 
47
  with gr.Row():
48
- url_input = gr.Textbox(lines=2, label='Enter valid image URL here..')
49
  img_output_from_url = gr.Image(shape=(650,650))
50
 
51
  with gr.Row():
52
  example_url = gr.Dataset(components=[url_input],samples=[[str(url)] for url in urls])
 
53
 
54
- url_but = gr.Button('Detect')
55
-
56
- #url_but.click(detect_objects,inputs=[options,url_input,img_input,slider_input],outputs=img_output_from_url,queue=True)
57
- #img_but.click(detect_objects,inputs=[options,url_input,img_input,slider_input],outputs=img_output_from_upload,queue=True)
58
- example_images.click(fn=set_example_image,inputs=[example_images],outputs=[img_input])
59
- example_url.click(fn=set_example_url,inputs=[example_url],outputs=[url_input])
60
 
61
- demo.launch(enable_queue=True)
 
 
 
 
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: telecom_object_detection.ipynb.
2
 
3
  # %% auto 0
4
+ __all__ = ['title', 'css', 'urls', 'flip_text', 'flip_image']
5
 
6
  # %% telecom_object_detection.ipynb 2
7
  import gradio as gr
 
16
  }
17
  '''
18
 
19
+ # %% telecom_object_detection.ipynb 5
20
+ import numpy as np
21
+ import gradio as gr
22
 
23
+ urls = ["https://c8.alamy.com/comp/J2AB4K/the-new-york-stock-exchange-on-the-wall-street-in-new-york-J2AB4K.jpg"]
24
 
25
+ def flip_text(x):
26
+ return x[::-1]
27
 
28
+ def flip_image(x):
29
+ return np.fliplr(x)
30
 
31
+ with gr.Blocks(css=css) as demo:
32
+
33
  gr.Markdown(title)
34
 
35
  with gr.Tabs():
36
+ with gr.TabItem("Image Upload"):
 
37
  with gr.Row():
38
+ image_input = gr.Image()
39
+ image_output = gr.Image()
 
40
  with gr.Row():
41
+ """example_images = gr.Dataset(components=[img_input],
42
  samples=[[path.as_posix()] for path in sorted(Path('images').rglob('*.jpg'))]
43
+ )"""
44
+ example_images = gr.Examples(
45
+ examples=[path.as_posix() for path in sorted(Path('images').rglob('*.jpg'))],
46
+ inputs=image_input
47
  )
48
+
49
+
50
+ image_button = gr.Button("Detect")
51
+
52
+ with gr.TabItem("Image URL"):
53
  with gr.Row():
54
+ text_input = gr.Textbox(lines=2, label='Enter valid image URL here..')
55
  img_output_from_url = gr.Image(shape=(650,650))
56
 
57
  with gr.Row():
58
  example_url = gr.Dataset(components=[url_input],samples=[[str(url)] for url in urls])
59
+ text_button = gr.Button("Detect")
60
 
 
 
 
 
 
 
61
 
62
+ text_button.click(flip_text, inputs=text_input, outputs=text_output)
63
+ image_button.click(flip_image, inputs=image_input, outputs=image_output)
64
+
65
+ demo.launch()