MaulikMadhavi commited on
Commit
8c5651e
1 Parent(s): 3e42073
Files changed (1) hide show
  1. app.py +57 -48
app.py CHANGED
@@ -1,55 +1,64 @@
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()
 
 
 
 
 
 
 
 
 
 
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()