Spaces:
Build error
Build error
Download app.py from SemihKST/foto_filter: direct link, hf CLI and curl.
- Browser
- Download file 5.2 kB
-
https://huggingface.co/spaces/SemihKST/foto_filter/resolve/main/app.py
- Command line
-
hf download hf://spaces/SemihKST/foto_filter/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SemihKST/foto_filter/resolve/main/app.py
5.2 kB
| #Gradio Kütüphanesi yükleme alanı | |
| #Jupyter' de aşağıdaki kütüphaneler yüklenecektir. | |
| #!pip install gradio | |
| #Numpy Kütüphanesi yükleme alanı | |
| #!pip install numpy | |
| #Etkileşimli Veri Görselleştirme Kütüphanesi yükleme alanı | |
| #!pip install ipywidgets | |
| #KÜTÜPHANELER => Programda kullanılacak gerekli kütüphaneler | |
| #(Görüntü kütüphanesi) | |
| import cv2 | |
| #(Oluşturulacak demo web sayfasının kütüphanesi) | |
| import gradio as gr | |
| #(çok boyutlu dizileri ve matrisleri destekleyen kütüphane) | |
| import numpy as np | |
| # Filtre Fonksiyonları | |
| def apply_gaussian_blur(frame): | |
| return cv2.GaussianBlur(frame, (15, 15), 0) | |
| def apply_sharpening_filter(frame): | |
| kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]]) | |
| return cv2.filter2D(frame, -1, kernel) | |
| def apply_edge_detection(frame): | |
| return cv2.Canny(frame, 100, 200) | |
| def apply_invert_filter(frame): | |
| return cv2.bitwise_not(frame) | |
| def adjust_brightness_contrast(frame, alpha=1.0, beta=0): | |
| return cv2.convertScaleAbs(frame, alpha=alpha, beta=beta) | |
| def apply_grayscale_filter(frame): | |
| return cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
| def apply_median_blur(frame): | |
| return cv2.medianBlur(frame, 15) | |
| def apply_bilateral_filter(frame): | |
| return cv2.bilateralFilter(frame, 9, 75, 75) | |
| def apply_HSV(frame): | |
| return cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) | |
| def apply_LAB(frame): | |
| return cv2.cvtColor(frame, cv2.COLOR_BGR2LAB) | |
| def apply_box_filter(frame): | |
| return cv2.boxFilter(frame, ddepth=-1, ksize=(7, 7), normalize=True) | |
| # Filtreleri uygulama fonksiyonu | |
| def apply_multiple_filters(filter_types, input_image): | |
| if input_image is None: | |
| return [], 0, 0 # Görüntü yüklenmemişse döner | |
| results = [] | |
| frame = input_image | |
| for filter_type in filter_types: | |
| if filter_type == "Gaussian Blur": | |
| filtered_frame = apply_gaussian_blur(frame) | |
| elif filter_type == "Sharpen": | |
| filtered_frame = apply_sharpening_filter(frame) | |
| elif filter_type == "Edge Detection": | |
| filtered_frame = apply_edge_detection(frame) | |
| elif filter_type == "Invert": | |
| filtered_frame = apply_invert_filter(frame) | |
| elif filter_type == "Brightness": | |
| filtered_frame = adjust_brightness_contrast(frame, alpha=1.0, beta=50) | |
| elif filter_type == "Grayscale": | |
| filtered_frame = apply_grayscale_filter(frame) | |
| elif filter_type == "Median Blur": | |
| filtered_frame = apply_median_blur(frame) | |
| elif filter_type == "Bilateral Filter": | |
| filtered_frame = apply_bilateral_filter(frame) | |
| elif filter_type == "HSV Filter": | |
| filtered_frame = apply_HSV(frame) | |
| elif filter_type == "LAB Filter": | |
| filtered_frame = apply_LAB(frame) | |
| elif filter_type == "Box Filter": | |
| filtered_frame = apply_box_filter(frame) | |
| results.append(filtered_frame) | |
| filter_apply_count = len(filter_types) # Uygulanan filtre sayısı | |
| filtered_image_count = len(results) # Filtrelenen görüntü sayısı | |
| return results, filter_apply_count, filtered_image_count | |
| # Çıktıyı temizlemek için fonksiyon | |
| def clear_output(): | |
| return [], 0, 0, 0 # Tüm sayaçları sıfırlar | |
| # Resim yükleme sayısını güncelleyen fonksiyon | |
| def update_image_upload_count(image): | |
| if image is not None: | |
| return 1 # Resim yüklendiğinde 1 döner | |
| else: | |
| return 0 | |
| # Gradio arayüzü | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# FOTOĞRAFLARI FİLTRELEME") | |
| # Sayaçları sağ üst köşeye yerleştirmek için Row bloğu kullanıyoruz | |
| with gr.Row(): | |
| image_upload_count_display = gr.Number(value=0, label="Resim Yükleme Sayısı", interactive=False) | |
| filter_apply_count_display = gr.Number(value=0, label="Filtre Uygulama Sayısı", interactive=False) | |
| filtered_image_count_display = gr.Number(value=0, label="Filtrelenmiş Resim Sayısı", interactive=False) | |
| # Filtre seçenekleri | |
| filter_type = gr.CheckboxGroup( | |
| label="Filtre Seçin", | |
| choices=["Gaussian Blur", "Sharpen", "Edge Detection", "Invert", "Brightness", "Grayscale", | |
| "Median Blur", "Bilateral Filter", "HSV Filter", "LAB Filter", "Box Filter"], | |
| value=["Gaussian Blur"], | |
| ) | |
| # Görüntü Yükleme Alanı | |
| input_image = gr.Image(label="Resim Yükle") | |
| input_image.change(fn=update_image_upload_count, inputs=input_image, outputs=image_upload_count_display) | |
| # Çıktı İçin Görüntüler (galeri olarak yan yana göstermek için) | |
| output_images = gr.Gallery(label="Seçilen Filtreler Uygulandı", columns=3) | |
| # Filtre uygulama butonu | |
| apply_button = gr.Button("Filtreleri Uygula") | |
| apply_button.click(fn=apply_multiple_filters, inputs=[filter_type, input_image], outputs=[output_images, filter_apply_count_display, filtered_image_count_display]) | |
| # Çıktıyı temizleme butonu | |
| clear_button = gr.Button("Temizle") | |
| clear_button.click(fn=clear_output, inputs=[], outputs=[output_images, filter_apply_count_display, filtered_image_count_display, image_upload_count_display]) | |
| # Gradio arayüzünün başlatıldığı kod | |
| demo.launch() | |