sedefiizm commited on
Commit
d3cdac2
·
verified ·
1 Parent(s): 19752bd

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -25
app.py CHANGED
@@ -1,34 +1,39 @@
1
- import streamlit as st
2
- from tensorflow.keras.models import load_model
 
 
3
  from PIL import Image
4
- import numpy as np
5
 
6
- model = load_model('cnn_model_epoch_100.h5')
7
 
8
- def process_image(img):
9
- img = img.resize((170, 170)) # Boyutu 170x170 piksel yaptık
10
- img = np.array(img) / 255.0 # Normalize ettik
11
- img = np.expand_dims(img, axis=0) # 0. ortada olsun diye sayfada
12
 
13
- st.title('Kanser Resmi sınıflandırma :cancer:')
14
- img_file = st.file_uploader('Bir Resim Seç', type=['jpeg', 'png'])
 
 
15
 
16
- if img_file is not None:
17
- img = Image.open(img_file)
18
- st.image(img, caption='Yüklenen resim')
19
- prediction = model.predict(img)
 
 
20
 
21
- st.title('Kanser Resmi Sınıflandırma :cancer:')
22
- st.write('Resim seç ve model kanser olup olmadığını tahmin etsin.')
23
 
24
- file = st.file_uploader('Bir Resim Seç', type=['jpg', 'jpeg', 'png'])
 
 
 
25
 
26
- if file is not None:
27
- img = Image.open(file)
28
- st.image(img, caption='Yüklenen resim')
29
- image = process_image(img)
30
- prediction = model.predict(image)
31
- predicted_class = np.argmax(prediction)
32
 
33
- class_names = ['Kanser Değil', 'Kanser']
34
- st.write(class_names[predicted_class])
 
1
+ import os
2
+ from flask import Flask, render_template, request, send_file
3
+ from diffusers import DiffusionPipeline
4
+ from io import BytesIO
5
  from PIL import Image
 
6
 
7
+ app = Flask(__name__)
8
 
9
+ # Modeli yükleyin (modeli sadece bir kez yüklemek için global tanımlıyoruz)
10
+ pipe = DiffusionPipeline.from_pretrained("sd-legacy/stable-diffusion-v1-5")
 
 
11
 
12
+ # Ana sayfayı render et
13
+ @app.route('/')
14
+ def index():
15
+ return render_template('index.html') # `templates` dizinine taşıdığınızı varsayıyoruz.
16
 
17
+ # Görsel üretme fonksiyonu
18
+ @app.route('/generate', methods=['POST'])
19
+ def generate_image():
20
+ try:
21
+ # Kullanıcıdan gelen prompt verisini al
22
+ prompt = request.form['prompt']
23
 
24
+ # Modelden görsel üretme
25
+ image = pipe(prompt).images[0]
26
 
27
+ # Görseli bir byte stream'e dönüştür
28
+ img_io = BytesIO()
29
+ image.save(img_io, 'PNG')
30
+ img_io.seek(0)
31
 
32
+ # Görseli kullanıcıya döndür
33
+ return send_file(img_io, mimetype='image/png')
34
+ except Exception as e:
35
+ # Hata durumunda kullanıcıya bir mesaj döndür
36
+ return f"Bir hata oluştu: {str(e)}"
 
37
 
38
+ if __name__ == '__main__':
39
+ app.run(debug=True)