IseaCraft commited on
Commit
a4f7ed2
1 Parent(s): d1e090f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -0
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import random
3
+ import uuid
4
+ import json
5
+ import gradio as gri
6
+ import numpy as np
7
+ from PIL import Image
8
+ import spaces
9
+ import torch
10
+ from fooocus import FooocusPipeline
11
+ from typing import Tuple
12
+
13
+ # Check for the Model Base..// (Commented out line)
14
+
15
+ bad_words = json.loads(os.getenv('BAD_WORDS', "[]"))
16
+ bad_words_negative = json.loads(os.getenv('BAD_WORDS_NEGATIVE', "[]"))
17
+ default_negative = os.getenv("default_negative", "")
18
+
19
+ def check_text(prompt, negative=""):
20
+ for i in bad_words:
21
+ if i in prompt:
22
+ return True
23
+ for i in bad_words_negative:
24
+ if i in negative:
25
+ return True
26
+ return False
27
+
28
+
29
+ style_list = [
30
+ {
31
+ "name": "2560 x 1440",
32
+ "prompt": "hyper-realistic 4K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
33
+ "negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
34
+ },
35
+ {
36
+ "name": "Photo",
37
+ "prompt": "cinematic photo {prompt}. 35mm photograph, film, bokeh, professional, 4k, highly detailed",
38
+ "negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
39
+ },
40
+ {
41
+ "name": "Cinematic",
42
+ "prompt": "cinematic still {prompt}. emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
43
+ "negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
44
+ },
45
+ {
46
+ "name": "Anime",
47
+ "prompt": "anime artwork {prompt}. anime style, key visual, vibrant, studio anime, highly detailed",
48
+ "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
49
+ },
50
+ {
51
+ "name": "3D Model",
52
+ "prompt": "professional 3d model {prompt}. octane render, highly detailed, volumetric, dramatic lighting",
53
+ "negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
54
+ },
55
+ {
56
+ "name": "(No style)",
57
+ "prompt": "{prompt}",
58
+ "negative_prompt": "",
59
+ },
60
+ ]
61
+
62
+ styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
63
+ STYLE_NAMES = list(styles.keys())
64
+ DEFAULT_STYLE_NAME = "2560 x 1440"
65
+
66
+ def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
67
+ p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
68
+ if not negative:
69
+ negative = ""
70
+ return p.replace("{prompt}", positive), n + negative
71
+
72
+
73
+ DESCRIPTION = """## MidJourneyHepzeka.com Ücretsiz ve Sınırsız Görsel Üretmek için Yapay Zeka Modeli"""
74
+
75
+
76
+ if not torch.cuda.is_available():
77
+ DESCRIPTION += "\n<p>⚠️Running on CPU, This may not work on CPU.</p>"
78
+
79
+ MAX_SEED = np.iinfo(np.int32).max
80
+ CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"
81
+ MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "2048"))
82
+ USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
83
+ ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
84
+ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
85
+ NUM_IMAGES_PER_PROMPT = 1
86
+
87
+ if torch.cuda.is_available():
88
+ pipe = FooocusPipeline.from_pretrained(
89
+ "SG161222/RealVisXL_V3.0_Turbo",
90
+