Phani1008 commited on
Commit
a766cbc
·
verified ·
1 Parent(s): f958e9c

Update pages/Types of Data.py

Browse files
Files changed (1) hide show
  1. pages/Types of Data.py +52 -0
pages/Types of Data.py CHANGED
@@ -378,6 +378,58 @@ print("Image Shape:", image_array.shape) # (Height, Width, Channels)
378
  print("Pixel Data (Top-left):", image_array[0, 0]) # Pixel value at (0, 0)
379
  """, language="python")
380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
  # Placeholder button for GitHub link
382
  if st.button("Jupyter Notebook 🔗 (Image)"):
383
  st.markdown("https://colab.research.google.com/drive/1BxJuxD1mzeuDnPIjwc-06J_GIU2JgO1_?usp=sharing")
 
378
  print("Pixel Data (Top-left):", image_array[0, 0]) # Pixel value at (0, 0)
379
  """, language="python")
380
 
381
+
382
+ from transformers import pipeline
383
+ import gradio as gr
384
+ from PIL import Image, ImageOps
385
+ import numpy as np
386
+ import random
387
+
388
+ # Function for image augmentation
389
+ def augment_image(image, crop_size, flip, rotation):
390
+ img = Image.fromarray(image)
391
+
392
+ # Crop
393
+ if crop_size > 0:
394
+ width, height = img.size
395
+ left = random.randint(0, crop_size)
396
+ top = random.randint(0, crop_size)
397
+ right = width - random.randint(0, crop_size)
398
+ bottom = height - random.randint(0, crop_size)
399
+ img = img.crop((left, top, right, bottom))
400
+
401
+ # Flip
402
+ if flip:
403
+ img = ImageOps.mirror(img)
404
+
405
+ # Rotate
406
+ if rotation != 0:
407
+ img = img.rotate(rotation, expand=True)
408
+
409
+ return np.array(img)
410
+
411
+ # Gradio interface
412
+ def interface(image, crop_size, flip, rotation):
413
+ augmented_image = augment_image(image, crop_size, flip, rotation)
414
+ return augmented_image
415
+
416
+ app = gr.Interface(
417
+ fn=interface,
418
+ inputs=[
419
+ gr.Image(type="numpy"),
420
+ gr.Slider(0, 100, step=1, label="Crop Size"),
421
+ gr.Checkbox(label="Flip"),
422
+ gr.Slider(0, 360, step=1, label="Rotation Angle")
423
+ ],
424
+ outputs=gr.Image(type="numpy"),
425
+ title="Image Augmentation Tool",
426
+ description="Upload an image to apply cropping, flipping, and rotation."
427
+ )
428
+
429
+ if __name__ == "__main__":
430
+ app.launch()
431
+
432
+
433
  # Placeholder button for GitHub link
434
  if st.button("Jupyter Notebook 🔗 (Image)"):
435
  st.markdown("https://colab.research.google.com/drive/1BxJuxD1mzeuDnPIjwc-06J_GIU2JgO1_?usp=sharing")