Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import os
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
def load_images(source_file):
|
| 7 |
+
images = []
|
| 8 |
+
for file in os.listdir(source_file):
|
| 9 |
+
if file.endswith(".jpg"):
|
| 10 |
+
image_path = os.path.join(source_file, file)
|
| 11 |
+
image = Image.open(image_path)
|
| 12 |
+
thumbnail = image.thumbnail((100, 100))
|
| 13 |
+
images.append(thumbnail)
|
| 14 |
+
return images
|
| 15 |
+
|
| 16 |
+
def show_thumbnails(source_file):
|
| 17 |
+
images = load_images(source_file)
|
| 18 |
+
return gr.outputs.ImageGroup(images)
|
| 19 |
+
|
| 20 |
+
iface = gr.Interface(fn=show_thumbnails, inputs="text", outputs="image", title="Image Thumbnails", description="Load all .jpg images in a folder and display their thumbnails.")
|
| 21 |
+
iface.launch()
|
| 22 |
+
|
| 23 |
+
|