MaulikMadhavi commited on
Commit
8596a66
1 Parent(s): 8c5651e

update app and requirements

Browse files
Files changed (2) hide show
  1. app.py +48 -56
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,64 +1,56 @@
1
  import gradio as gr
2
- # import cv2
3
- # from PIL import Image
4
- # from pillow_heif import register_heif_opener
5
- # import numpy as np
6
- # import imghdr
7
 
8
- # def process_image(input_image, width = None, height = None):
9
- # # Process the image here
10
- # # For example, you can apply some image filters or transformations
11
- # if input_image:
12
- # # Convert the PIL image to OpenCV format
13
- # image = Image.open(input_image)
14
- # image = np.array(image)
15
- # if width is None:
16
- # width = image.shape[1]
17
- # if height is None:
18
- # height = image.shape[0]
19
- # # Apply some image processing
20
- # print(f"Width: {width}, Height: {height}")
21
- # image = cv2.resize(image, (height, width))
22
- # print(f"Image shape: {image.shape}")
23
- # return image
24
- # else:
25
- # return None
26
 
27
- # def display_image_info(input_image):
28
- # if not input_image:
29
- # return "No image uploaded"
30
- # try:
31
- # format = imghdr.what(input_image)
32
- # return f"The format of the image is '{format}'"
33
- # except:
34
- # return f"The image format is unknown. However the file extension is '{input_image.split('.')[-1]}'"
35
 
36
- # with gr.Blocks("Image-Processing") as demo:
37
- # with gr.Row():
38
- # with gr.Column():
39
- # input_image = gr.Image("input_image", type="filepath")
40
- # with gr.Column():
41
- # output_image = gr.Image("output_image", type="filepath")
42
- # # ========= For width and height ==========
43
- # with gr.Row():
44
- # width = gr.Slider(1, 1000, value=256, label="Width")
45
- # height = gr.Slider(1, 1000, value=192, label="Height")
46
- # with gr.Row():
47
- # output_textbox = gr.Textbox("output_textbox", type="text", label="Output Textbox")
48
 
49
- # input_image.change(process_image, [input_image, width, height], output_image)
50
- # input_image.change(display_image_info, input_image, output_textbox)
51
 
52
- # width.change(process_image, [input_image, width, height], output_image)
53
- # height.change(process_image, [input_image, width, height], output_image)
54
 
55
- # demo.launch()
56
 
57
-
58
- import gradio as gr
59
-
60
- def greet(name):
61
- return "Hello " + name + "!!"
62
-
63
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
64
- iface.launch()
 
1
  import gradio as gr
2
+ import cv2
3
+ from PIL import Image
4
+ from pillow_heif import register_heif_opener
5
+ import numpy as np
6
+ import imghdr
7
 
8
+ def process_image(input_image, width = None, height = None):
9
+ # Process the image here
10
+ # For example, you can apply some image filters or transformations
11
+ if input_image:
12
+ # Convert the PIL image to OpenCV format
13
+ image = Image.open(input_image)
14
+ image = np.array(image)
15
+ if width is None:
16
+ width = image.shape[1]
17
+ if height is None:
18
+ height = image.shape[0]
19
+ # Apply some image processing
20
+ print(f"Width: {width}, Height: {height}")
21
+ image = cv2.resize(image, (height, width))
22
+ print(f"Image shape: {image.shape}")
23
+ return image
24
+ else:
25
+ return None
26
 
27
+ def display_image_info(input_image):
28
+ if not input_image:
29
+ return "No image uploaded"
30
+ try:
31
+ format = imghdr.what(input_image)
32
+ return f"The format of the image is '{format}'"
33
+ except:
34
+ return f"The image format is unknown. However the file extension is '{input_image.split('.')[-1]}'"
35
 
36
+ with gr.Blocks("Image-Processing") as demo:
37
+ with gr.Row():
38
+ with gr.Column():
39
+ input_image = gr.Image("input_image", type="filepath")
40
+ with gr.Column():
41
+ output_image = gr.Image("output_image", type="filepath")
42
+ # ========= For width and height ==========
43
+ with gr.Row():
44
+ width = gr.Slider(1, 1000, value=256, label="Width")
45
+ height = gr.Slider(1, 1000, value=192, label="Height")
46
+ with gr.Row():
47
+ output_textbox = gr.Textbox("output_textbox", type="text", label="Output Textbox")
48
 
49
+ input_image.change(process_image, [input_image, width, height], output_image)
50
+ input_image.change(display_image_info, input_image, output_textbox)
51
 
52
+ width.change(process_image, [input_image, width, height], output_image)
53
+ height.change(process_image, [input_image, width, height], output_image)
54
 
55
+ demo.launch()
56
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  pillow
2
- pillow-avif-plugin
 
 
1
  pillow
2
+ pillow-avif-plugin
3
+ opencv-python