Spaces:
Sleeping
Sleeping
Taha Razzaq
commited on
Commit
·
92494bc
1
Parent(s):
37ea0b9
errors fixed + preview updated
Browse files
app.py
CHANGED
|
@@ -1,23 +1,34 @@
|
|
| 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
|
| 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 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Function to process uploaded images
|
| 23 |
def process_images(images):
|
|
@@ -28,8 +39,9 @@ def process_images(images):
|
|
| 28 |
processed_imgs = []
|
| 29 |
|
| 30 |
for img in images:
|
| 31 |
-
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
return gr.update(visible=True, value=original_imgs), gr.update(visible=True, value=processed_imgs)
|
| 35 |
|
|
@@ -60,4 +72,4 @@ with gr.Blocks() as demo:
|
|
| 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()
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from PIL import Image, ImageOps
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt # needed for plt.imread
|
|
|
|
| 5 |
def load_sample_images():
|
| 6 |
sample_paths = ["sample1.jpg", "sample2.jpg"] # Must be in the same folder as your script
|
| 7 |
original_imgs = [Image.open(path) for path in sample_paths]
|
| 8 |
processed_imgs = [process_image(path) for path in sample_paths]
|
| 9 |
return gr.update(visible=True, value=original_imgs), gr.update(visible=True, value=processed_imgs)
|
| 10 |
|
| 11 |
+
|
| 12 |
+
|
| 13 |
# Image processing function (you can replace this)
|
| 14 |
def process_image(img: Image.Image) -> Image.Image:
|
| 15 |
+
# Read image using matplotlib
|
| 16 |
+
img_np = plt.imread(img)
|
| 17 |
+
if img_np.ndim == 3 and img_np.shape[2] > 3:
|
| 18 |
+
img_np = img_np[:, :, :3]
|
| 19 |
+
|
| 20 |
+
# Convert to grayscale for original image display
|
| 21 |
+
gray_img = ImageOps.grayscale(Image.fromarray((img_np * 255).astype(np.uint8)))
|
| 22 |
+
|
| 23 |
+
# Run your WTA processing (dummy if not available)
|
| 24 |
+
# Replace this line with actual WTA processing
|
| 25 |
+
img_tensor = wta.wta(img_np).numpy() # Assuming returns shape (1, H, W)
|
| 26 |
+
|
| 27 |
+
# Convert processed image to inferno colormap
|
| 28 |
+
inferno_colored = plt.cm.inferno(img_tensor[0])
|
| 29 |
+
inferno_img = Image.fromarray((inferno_colored[:, :, :3] * 255).astype(np.uint8))
|
| 30 |
+
|
| 31 |
+
return gray_img, inferno_img
|
| 32 |
|
| 33 |
# Function to process uploaded images
|
| 34 |
def process_images(images):
|
|
|
|
| 39 |
processed_imgs = []
|
| 40 |
|
| 41 |
for img in images:
|
| 42 |
+
original_gray_scale_img, inferno_img = process_image(img)
|
| 43 |
+
original_imgs.append(original_gray_scale_img)
|
| 44 |
+
processed_imgs.append(inferno_img)
|
| 45 |
|
| 46 |
return gr.update(visible=True, value=original_imgs), gr.update(visible=True, value=processed_imgs)
|
| 47 |
|
|
|
|
| 72 |
|
| 73 |
# example_files = [["sample1.jpg", "sample2.jpg"], ["sample2.jpg"]]
|
| 74 |
# gr.Examples(examples=example_files, inputs=[file_input], label="Try one of our example samples")
|
| 75 |
+
demo.launch(debug=True)
|