Taha Razzaq commited on
Commit
8c986fb
·
1 Parent(s): 1b80245
Files changed (4) hide show
  1. app.py +63 -0
  2. requirements.txt +6 -0
  3. sample1.jpg +0 -0
  4. sample2.jpg +0 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import keras
2
+ import numpy as np
3
+ import gradio as gr
4
+ from tibblingai import wta
5
+ from PIL import Image, ImageOps
6
+ import matplotlib.pyplot as plt
7
+
8
+
9
+ def load_sample_images():
10
+ sample_paths = ["sample1.jpg", "sample2.jpg"] # Must be in the same folder as your script
11
+ original_imgs = [Image.open(path) for path in sample_paths]
12
+ processed_imgs = [process_image(path) for path in sample_paths]
13
+ return gr.update(visible=True, value=original_imgs), gr.update(visible=True, value=processed_imgs)
14
+
15
+ # Image processing function (you can replace this)
16
+ def process_image(img: Image.Image) -> Image.Image:
17
+ img_tensor = wta.wta(plt.imread(img)).numpy()
18
+ print(img_tensor.shape)
19
+ # image_array = np.squeeze(img_tensor)
20
+ return img_tensor[0]
21
+
22
+ # Function to process uploaded images
23
+ def process_images(images):
24
+ if not isinstance(images, list):
25
+ images = [images]
26
+
27
+ original_imgs = []
28
+ processed_imgs = []
29
+
30
+ for img in images:
31
+ original_imgs.append(img)
32
+ processed_imgs.append(process_image(img))
33
+
34
+ return gr.update(visible=True, value=original_imgs), gr.update(visible=True, value=processed_imgs)
35
+
36
+ # Gradio Interface
37
+ with gr.Blocks() as demo:
38
+ gr.Markdown("## Upload Image(s) for Processing")
39
+
40
+ # File component (no preview shown here)
41
+ file_input = gr.File(file_types=["image"],file_count="multiple", label="Upload Images")
42
+
43
+ with gr.Row():
44
+ original_gallery = gr.Gallery(label="Original Images", visible=False)
45
+ processed_gallery = gr.Gallery(label="Processed Images", visible=False)
46
+
47
+ file_input.change(fn=process_images, inputs=file_input, outputs=[original_gallery, processed_gallery])
48
+ with gr.Row():
49
+ with gr.Column(scale=0, min_width=300):
50
+ load_examples_btn = gr.Button("Run WTA on sample images")
51
+ load_examples_btn.click(fn=load_sample_images, outputs=[original_gallery, processed_gallery])
52
+
53
+
54
+ # 🆕 Examples section
55
+ # examples = gr.Examples(
56
+ # examples=[["sample1.jpg"], ["sample2.jpg"]],
57
+ # inputs=file_input,
58
+ # label="Example Images"
59
+ # )
60
+
61
+ # example_files = [["sample1.jpg", "sample2.jpg"], ["sample2.jpg"]]
62
+ # gr.Examples(examples=example_files, inputs=[file_input], label="Try one of our example samples")
63
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ pillow
3
+ matplotlib
4
+ numpy
5
+ tibblingai
6
+ keras
sample1.jpg ADDED
sample2.jpg ADDED