Update app.py
Browse files
app.py
CHANGED
@@ -1,113 +1,113 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
from tensorflow.keras.models import load_model
|
4 |
-
from tensorflow.keras.preprocessing.image import img_to_array
|
5 |
-
from PIL import Image
|
6 |
-
import io
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
model = load_model('Dog_Cat_64-64_512Dense.h5')
|
11 |
-
|
12 |
-
def predict_image(img):
|
13 |
-
if img is None:
|
14 |
-
return None
|
15 |
-
|
16 |
-
|
17 |
-
img = Image.fromarray(img.astype('uint8'), 'RGB')
|
18 |
-
img = img.resize((64, 64)) # Modelin giriş boyutu
|
19 |
-
img_array = img_to_array(img)
|
20 |
-
img_array = np.expand_dims(img_array, axis=0)
|
21 |
-
|
22 |
-
|
23 |
-
prediction = model.predict(img_array)[0][0] # Tahmin
|
24 |
-
|
25 |
-
tahmin = "Köpek" if prediction > 0.5 else "Kedi"
|
26 |
-
dogruluk = prediction if prediction > 0.5 else 1 - prediction
|
27 |
-
|
28 |
-
|
29 |
-
sonuc = f"""
|
30 |
-
<div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 15px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
|
31 |
-
<h2 style="font-size: 28px; margin-bottom: 15px;">Tahmin Sonucu</h2>
|
32 |
-
<p style="font-size: 24px; margin-bottom: 10px;">Bu resim büyük olasılıkla bir <b>{tahmin}</b>!</p>
|
33 |
-
<p style="font-size: 18px;">Tahmin Güveni: {dogruluk*100:.2f}%</p>
|
34 |
-
<div style="background-color: rgba(255,255,255,0.3); width: 80%; height: 20px; margin: 15px auto; border-radius: 10px;">
|
35 |
-
<div style="background-color: #4CAF50; width: {dogruluk*100}%; height: 100%; border-radius: 10px; transition: width 0.5s ease-in-out;"></div>
|
36 |
-
</div>
|
37 |
-
</div>
|
38 |
-
"""
|
39 |
-
|
40 |
-
return sonuc
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
descr = """
|
45 |
-
Bu uygulama, yapay zeka teknolojisini kullanarak kedi ve köpek resimlerini sınıflandırır.
|
46 |
-
Yükleyeceğiniz resmin kedi mi yoksa köpek mi olduğunu tahmin eder.
|
47 |
-
|
48 |
-
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap" rel="stylesheet">
|
49 |
-
|
50 |
-
<div style="display: flex; justify-content: space-between; font-family: 'Arial', sans-serif;">
|
51 |
-
<div style="flex: 1; padding-right: 10px;">
|
52 |
-
<h2>Nasıl Kullanılır?</h2>
|
53 |
-
<ol>
|
54 |
-
<li>Sağ taraftaki alana bir resim yükleyin veya sürükleyip bırakın.</li>
|
55 |
-
<li>Resim yüklendikten sonra, model otomatik olarak tahminde bulunacaktır.</li>
|
56 |
-
<li>Sonuç ve doğruluk oranı gözükecektir.</li>
|
57 |
-
</ol>
|
58 |
-
</div>
|
59 |
-
<div style="flex: 1; padding-left: 10px;">
|
60 |
-
<h2>Not</h2>
|
61 |
-
<ul>
|
62 |
-
<li>Desteklenen resim formatları: JPG, JPEG, PNG, WEPB</li>
|
63 |
-
<li>Model her zaman %100 doğru olmayabilir. Eğlenmek ve öğrenmek için kullanın.</li>
|
64 |
-
<li>Resimlerin net ve anlaşılır olması doğruluk oranını artıracaktır.</li>
|
65 |
-
</ul>
|
66 |
-
</div>
|
67 |
-
</div>
|
68 |
-
|
69 |
-
<p style="font-size: 20px; font-family: 'Poppins', sans-comic; font-style: bold;">
|
70 |
-
Daha fazla açıklama yok bir kedi veya köpek resmi yükleyin ve sonucu görün!
|
71 |
-
</p>
|
72 |
-
"""
|
73 |
-
footer = """
|
74 |
-
<div style="text-align: center; font-size: 14px; color: #666;">
|
75 |
-
<p>
|
76 |
-
<a href="https://github.com/yusuffenes" style="margin-right: 15px; text-decoration: none;font-style: bold; color: #666;">GitHub</a>
|
77 |
-
<a href="https://www.linkedin.com/in/yusufenesbudak" style="margin-right: 15px; text-decoration: none;font-style: bold; color: #666;">LinkedIn</a>
|
78 |
-
<span>yusufenes</span>
|
79 |
-
</p>
|
80 |
-
<p style="margin-top: 10px;">
|
81 |
-
<span>🐾 Kedi-Köpek Tahmin Uygulaması 🐾</span>
|
82 |
-
<span style="margin-left: 15px;">© 2024 ©</span>
|
83 |
-
</p>
|
84 |
-
</div>
|
85 |
-
|
86 |
-
"""
|
87 |
-
|
88 |
-
myGradioAppInterface = gr.Interface(
|
89 |
-
fn=predict_image,
|
90 |
-
inputs=gr.Image(type="numpy", label="Resim Yükle"),
|
91 |
-
outputs=gr.HTML(label="Tahmin Sonucu"),
|
92 |
-
title="🐾 Kedi/Köpek Tahmin Uygulaması 🐾",
|
93 |
-
|
94 |
-
description=descr,
|
95 |
-
article=footer,
|
96 |
-
examples=[
|
97 |
-
["
|
98 |
-
["
|
99 |
-
["
|
100 |
-
["
|
101 |
-
|
102 |
-
],
|
103 |
-
theme=gr.themes.Soft().set(
|
104 |
-
body_background_fill="#f0f2f6",
|
105 |
-
button_primary_background_fill="#4a90e2",
|
106 |
-
button_shadow="#205493",
|
107 |
-
),
|
108 |
-
allow_flagging=False,
|
109 |
-
|
110 |
-
)
|
111 |
-
|
112 |
-
|
113 |
myGradioAppInterface.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
from tensorflow.keras.preprocessing.image import img_to_array
|
5 |
+
from PIL import Image
|
6 |
+
import io
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
model = load_model('Dog_Cat_64-64_512Dense.h5')
|
11 |
+
|
12 |
+
def predict_image(img):
|
13 |
+
if img is None:
|
14 |
+
return None
|
15 |
+
|
16 |
+
|
17 |
+
img = Image.fromarray(img.astype('uint8'), 'RGB')
|
18 |
+
img = img.resize((64, 64)) # Modelin giriş boyutu
|
19 |
+
img_array = img_to_array(img)
|
20 |
+
img_array = np.expand_dims(img_array, axis=0)
|
21 |
+
|
22 |
+
|
23 |
+
prediction = model.predict(img_array)[0][0] # Tahmin
|
24 |
+
|
25 |
+
tahmin = "Köpek" if prediction > 0.5 else "Kedi"
|
26 |
+
dogruluk = prediction if prediction > 0.5 else 1 - prediction
|
27 |
+
|
28 |
+
|
29 |
+
sonuc = f"""
|
30 |
+
<div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 15px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
|
31 |
+
<h2 style="font-size: 28px; margin-bottom: 15px;">Tahmin Sonucu</h2>
|
32 |
+
<p style="font-size: 24px; margin-bottom: 10px;">Bu resim büyük olasılıkla bir <b>{tahmin}</b>!</p>
|
33 |
+
<p style="font-size: 18px;">Tahmin Güveni: {dogruluk*100:.2f}%</p>
|
34 |
+
<div style="background-color: rgba(255,255,255,0.3); width: 80%; height: 20px; margin: 15px auto; border-radius: 10px;">
|
35 |
+
<div style="background-color: #4CAF50; width: {dogruluk*100}%; height: 100%; border-radius: 10px; transition: width 0.5s ease-in-out;"></div>
|
36 |
+
</div>
|
37 |
+
</div>
|
38 |
+
"""
|
39 |
+
|
40 |
+
return sonuc
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
descr = """
|
45 |
+
Bu uygulama, yapay zeka teknolojisini kullanarak kedi ve köpek resimlerini sınıflandırır.
|
46 |
+
Yükleyeceğiniz resmin kedi mi yoksa köpek mi olduğunu tahmin eder.
|
47 |
+
|
48 |
+
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap" rel="stylesheet">
|
49 |
+
|
50 |
+
<div style="display: flex; justify-content: space-between; font-family: 'Arial', sans-serif;">
|
51 |
+
<div style="flex: 1; padding-right: 10px;">
|
52 |
+
<h2>Nasıl Kullanılır?</h2>
|
53 |
+
<ol>
|
54 |
+
<li>Sağ taraftaki alana bir resim yükleyin veya sürükleyip bırakın.</li>
|
55 |
+
<li>Resim yüklendikten sonra, model otomatik olarak tahminde bulunacaktır.</li>
|
56 |
+
<li>Sonuç ve doğruluk oranı gözükecektir.</li>
|
57 |
+
</ol>
|
58 |
+
</div>
|
59 |
+
<div style="flex: 1; padding-left: 10px;">
|
60 |
+
<h2>Not</h2>
|
61 |
+
<ul>
|
62 |
+
<li>Desteklenen resim formatları: JPG, JPEG, PNG, WEPB</li>
|
63 |
+
<li>Model her zaman %100 doğru olmayabilir. Eğlenmek ve öğrenmek için kullanın.</li>
|
64 |
+
<li>Resimlerin net ve anlaşılır olması doğruluk oranını artıracaktır.</li>
|
65 |
+
</ul>
|
66 |
+
</div>
|
67 |
+
</div>
|
68 |
+
|
69 |
+
<p style="font-size: 20px; font-family: 'Poppins', sans-comic; font-style: bold;">
|
70 |
+
Daha fazla açıklama yok bir kedi veya köpek resmi yükleyin ve sonucu görün!
|
71 |
+
</p>
|
72 |
+
"""
|
73 |
+
footer = """
|
74 |
+
<div style="text-align: center; font-size: 14px; color: #666;">
|
75 |
+
<p>
|
76 |
+
<a href="https://github.com/yusuffenes" style="margin-right: 15px; text-decoration: none;font-style: bold; color: #666;">GitHub</a>
|
77 |
+
<a href="https://www.linkedin.com/in/yusufenesbudak" style="margin-right: 15px; text-decoration: none;font-style: bold; color: #666;">LinkedIn</a>
|
78 |
+
<span>yusufenes</span>
|
79 |
+
</p>
|
80 |
+
<p style="margin-top: 10px;">
|
81 |
+
<span>🐾 Kedi-Köpek Tahmin Uygulaması 🐾</span>
|
82 |
+
<span style="margin-left: 15px;">© 2024 ©</span>
|
83 |
+
</p>
|
84 |
+
</div>
|
85 |
+
|
86 |
+
"""
|
87 |
+
|
88 |
+
myGradioAppInterface = gr.Interface(
|
89 |
+
fn=predict_image,
|
90 |
+
inputs=gr.Image(type="numpy", label="Resim Yükle"),
|
91 |
+
outputs=gr.HTML(label="Tahmin Sonucu"),
|
92 |
+
title="🐾 Kedi/Köpek Tahmin Uygulaması 🐾",
|
93 |
+
|
94 |
+
description=descr,
|
95 |
+
article=footer,
|
96 |
+
examples=[
|
97 |
+
["ornek_kedi.jpg"],
|
98 |
+
["ornek_kopek.jpg"],
|
99 |
+
["ornek_kedi2.jpg"],
|
100 |
+
["ornek_kopek2.jpg"]
|
101 |
+
|
102 |
+
],
|
103 |
+
theme=gr.themes.Soft().set(
|
104 |
+
body_background_fill="#f0f2f6",
|
105 |
+
button_primary_background_fill="#4a90e2",
|
106 |
+
button_shadow="#205493",
|
107 |
+
),
|
108 |
+
allow_flagging=False,
|
109 |
+
|
110 |
+
)
|
111 |
+
|
112 |
+
|
113 |
myGradioAppInterface.launch()
|