Andrei Zhytkevich commited on
Commit
18bd2aa
1 Parent(s): aa5ae13

add image source

Browse files
Files changed (3) hide show
  1. README.md +2 -1
  2. app.py +17 -11
  3. nodemon.json +6 -0
README.md CHANGED
@@ -15,8 +15,9 @@ license: wtfpl
15
  This is Gradio project for reading and displaying an image and its metadata from url.
16
 
17
  ## Usage
18
- - Copy image address;
19
  - Paste it into the **url** field
 
20
  - Submit
21
 
22
  **Generation parameters** text can be directly used in AUTOMATIC1111 UI
 
15
  This is Gradio project for reading and displaying an image and its metadata from url.
16
 
17
  ## Usage
18
+ - Copy image address
19
  - Paste it into the **url** field
20
+ - or Drag and Drop/Upload image
21
  - Submit
22
 
23
  **Generation parameters** text can be directly used in AUTOMATIC1111 UI
app.py CHANGED
@@ -2,17 +2,23 @@ import gradio as gr
2
  from PIL import Image
3
  from urllib.request import Request, urlopen
4
 
5
- def display_image_from_url(url):
6
- if url == '':
7
- return None, ""
8
 
9
- req = Request(
10
- url=url,
11
- headers={'User-Agent': 'Mozilla/5.0'}
12
- )
13
- res = urlopen(req)
14
- image = Image.open(res)
15
- image.load()
 
 
 
 
 
 
16
 
17
  parameters = "Parameters have been erased from this image"
18
  if 'parameters' in image.info:
@@ -20,5 +26,5 @@ def display_image_from_url(url):
20
 
21
  return image, parameters, image.info
22
 
23
- server = gr.Interface(display_image_from_url, "text", ["image", gr.Textbox(label="Generation Parameters"), gr.Textbox(label="Metadata")])
24
  server.launch()
 
2
  from PIL import Image
3
  from urllib.request import Request, urlopen
4
 
5
+ def display_image_from_url(url, input_image):
6
+ if url == '' and input_image is None:
7
+ return None, "", ""
8
 
9
+ image = None
10
+ if url != '':
11
+ req = Request(
12
+ url=url,
13
+ headers={'User-Agent': 'Mozilla/5.0'}
14
+ )
15
+ res = urlopen(req)
16
+ image = Image.open(res)
17
+ image.load()
18
+
19
+
20
+ if input_image is not None:
21
+ image = input_image
22
 
23
  parameters = "Parameters have been erased from this image"
24
  if 'parameters' in image.info:
 
26
 
27
  return image, parameters, image.info
28
 
29
+ server = gr.Interface(display_image_from_url, ["text", gr.Image(type='pil')], [gr.Image(type='pil'), gr.Textbox(label="Generation Parameters"), gr.Textbox(label="Metadata")])
30
  server.launch()
nodemon.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "verbose": true,
3
+ "execMap": {
4
+ "py": "/usr/bin/python3"
5
+ }
6
+ }