erhanmeydan commited on
Commit
ee0b822
·
verified ·
1 Parent(s): 29b9f2e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image, ImageDraw
3
+ import numpy as np
4
+
5
+ # Halftone efekti fonksiyonu
6
+ def halftone_effect(image, shape="circle", sample=10):
7
+ # Görüntüyü gri tonlamaya çevir
8
+ img = image.convert("L")
9
+ img_array = np.array(img)
10
+ height, width = img_array.shape
11
+
12
+ # Çıktı görüntüsü için boş bir tuval oluştur
13
+ output = Image.new("L", (width, height), 255)
14
+ draw = ImageDraw.Draw(output)
15
+
16
+ # Şekil boyutunu ve aralığını ayarla
17
+ for y in range(0, height, sample):
18
+ for x in range(0, width, sample):
19
+ # Piksel yoğunluğunu hesapla (0-255)
20
+ intensity = img_array[y, x]
21
+ # Yoğunluğa göre şeklin boyutunu ölçekle
22
+ radius = (255 - intensity) / 255 * (sample / 2)
23
+
24
+ # Şekil çizimi
25
+ if shape == "circle":
26
+ draw.ellipse(
27
+ [x - radius, y - radius, x + radius, y + radius],
28
+ fill=0
29
+ )
30
+ elif shape == "square":
31
+ draw.rectangle(
32
+ [x - radius, y - radius, x + radius, y + radius],
33
+ fill=0
34
+ )
35
+ elif shape == "triangle":
36
+ draw.polygon(
37
+ [(x, y - radius), (x - radius, y + radius), (x + radius, y + radius)],
38
+ fill=0
39
+ )
40
+
41
+ return output
42
+
43
+ # Gradio arayüzü
44
+ def gradio_interface(image, shape):
45
+ if image is None:
46
+ return None
47
+ result = halftone_effect(image, shape=shape)
48
+ return result
49
+
50
+ # Arayüzü oluştur
51
+ interface = gr.Interface(
52
+ fn=gradio_interface,
53
+ inputs=[
54
+ gr.Image(type="pil", label="Bir görüntü yükle"),
55
+ gr.Dropdown(choices=["circle", "square", "triangle"], label="Şekil Seçimi", value="circle")
56
+ ],
57
+ outputs=gr.Image(type="pil", label="Halftone Efektli Görüntü"),
58
+ title="Halftone Efekt Uygulaması",
59
+ description="Bir görüntü yükleyin ve halftone efekti için bir şekil seçin."
60
+ )
61
+
62
+ # Uygulamayı başlat
63
+ interface.launch()