lmellory commited on
Commit
69dc9b9
·
verified ·
1 Parent(s): 123dd26

create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
3
+ import torch
4
+ from transformers import pipeline
5
+
6
+ # Загрузка модели Stable Diffusion (оптимизированная)
7
+ pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
8
+ pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
9
+ pipe.to("cuda" if torch.cuda.is_available() else "cpu")
10
+
11
+ # Простая NSFW-проверка (из твоего курса по security)
12
+ nsfw_detector = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english") # Замени на NSFW модель если нужно
13
+
14
+ def generate_image(prompt, image=None):
15
+ if nsfw_detector(prompt)[0]['label'] == 'NEGATIVE': # Простая проверка на плохой промпт
16
+ return "Prompt not safe - try again!"
17
+
18
+ # Генерация
19
+ result = pipe(prompt).images[0]
20
+
21
+ # Если загружено фото — базовый style transfer (можно расширить)
22
+ if image:
23
+ # Здесь можно добавить face swap или style transfer (расширь позже)
24
+ result = result.resize(image.size) # Простой resize для комбо
25
+
26
+ return result
27
+
28
+ # Интерфейс Gradio
29
+ iface = gr.Interface(
30
+ fn=generate_image,
31
+ inputs=[gr.Textbox(label="Description (e.g., 'Romantic couple on sunset beach')"), gr.Image(label="Upload photo for style (optional)")],
32
+ outputs=gr.Image(label="Generated Image"),
33
+ title="Epic AI Art Generator",
34
+ description="Generate awesome images! Made for my girl ❤️"
35
+ )
36
+
37
+ iface.launch()