TamerTokgoz commited on
Commit
4e2b486
·
verified ·
1 Parent(s): 24bef22

Create appp.py

Browse files
Files changed (1) hide show
  1. appp.py +68 -0
appp.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # --- SAYFA AYARLARI ---
7
+ st.set_page_config(page_title="Monet Stil Transferi", layout="centered")
8
+
9
+ st.title("🎨 Fotoğrafını Monet Tablosuna Dönüştür")
10
+ st.write("Fotoğrafını yükle ve yapay zekanın onu Claude Monet tarzında bir sanat eserine dönüştürmesini izle!")
11
+
12
+ # --- MODELİ YÜKLEME ---
13
+ # Cache kullanarak modelin her seferinde tekrar yüklenmesini engelliyoruz
14
+ @st.cache_resource
15
+ def load_gan_model():
16
+ # Modelini .h5 formatında yüklüyoruz.
17
+ # Not: Eğer Custom Layer (InstanceNormalization) kullandıysan 'custom_objects' eklemelisin.
18
+ model = tf.keras.models.load_model('monet_generator_model.h5', compile=False)
19
+ return model
20
+
21
+ model = load_gan_model()
22
+
23
+ # --- GÖRÜNTÜ ÖN İŞLEME ---
24
+ def preprocess_image(image):
25
+ image = image.resize((256, 256))
26
+ image = np.array(image)
27
+ image = (image.astype(np.float32) / 127.5) - 1 # [-1, 1] aralığına normalize et
28
+ image = np.expand_dims(image, axis=0) # Batch boyutu ekle
29
+ return image
30
+
31
+ def postprocess_image(prediction):
32
+ prediction = prediction[0] # Batch boyutunu kaldır
33
+ prediction = (prediction * 0.5 + 0.5) * 255 # [0, 255] aralığına geri dön
34
+ return prediction.astype(np.uint8)
35
+
36
+ # --- ARAYÜZ ---
37
+ uploaded_file = st.file_uploader("Bir fotoğraf seçin...", type=["jpg", "jpeg", "png"])
38
+
39
+ if uploaded_file is not None:
40
+ # Orijinal resmi göster
41
+ input_image = Image.open(uploaded_file).convert("RGB")
42
+
43
+ col1, col2 = st.columns(2)
44
+
45
+ with col1:
46
+ st.subheader("Orijinal Fotoğraf")
47
+ st.image(input_image, use_column_width=True)
48
+
49
+ # Dönüştürme butonu
50
+ if st.button("Dönüştür ✨"):
51
+ with st.spinner('Sanat eseri oluşturuluyor...'):
52
+ # İşleme
53
+ processed_img = preprocess_image(input_image)
54
+ prediction = model.predict(processed_img)
55
+ output_image = postprocess_image(prediction)
56
+
57
+ with col2:
58
+ st.subheader("Monet Tarzı")
59
+ st.image(output_image, use_column_width=True)
60
+
61
+ st.success("Tamamlandı!")
62
+
63
+ # İndirme butonu
64
+ result_img = Image.fromarray(output_image)
65
+ st.download_button(label="Resmi İndir",
66
+ data=uploaded_file, # Örnek amaçlı, gerçekte resmi byte'a çevirmelisiniz
67
+ file_name="monet_style.jpg",
68
+ mime="image/jpeg")