CryptoCreeper commited on
Commit
197d222
·
verified ·
1 Parent(s): b3671f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -17,11 +17,18 @@ image_model_id = "SimianLuo/LCM_Dreamshaper_v7"
17
  image_pipe = DiffusionPipeline.from_pretrained(image_model_id)
18
  image_pipe.to(device)
19
 
20
- def clean_prompt(text):
21
- forbidden_words = ["4k", "8k", "high res", "high resolution", "hd", "ultra detailed", "masterpiece"]
22
  for word in forbidden_words:
23
- text = re.sub(word, "", text, flags=re.IGNORECASE)
 
24
  text = re.sub(r'\s+', ' ', text).strip()
 
 
 
 
 
 
25
  return text
26
 
27
  def generate_workflow(prompt, width, height, steps):
@@ -30,11 +37,8 @@ def generate_workflow(prompt, width, height, steps):
30
  enhanced_results = enhancer_pipe(prompt, max_length=60, num_return_sequences=1)
31
  raw_enhanced = enhanced_results[0]['generated_text']
32
 
33
- refined_prompt = clean_prompt(raw_enhanced)
34
 
35
- if "centered" not in refined_prompt.lower():
36
- refined_prompt += ", centered in the image"
37
-
38
  yield "🎨 Generating (Image generator AI)...", None, refined_prompt
39
 
40
  image = image_pipe(
@@ -49,7 +53,7 @@ def generate_workflow(prompt, width, height, steps):
49
 
50
  yield "✅ Ready", image, refined_prompt
51
 
52
- with gr.Blocks(theme=gr.themes.Soft(), title="AI Image Lab") as demo:
53
  gr.Markdown("# 🎨 AI Image Lab")
54
 
55
  with gr.Row():
@@ -80,4 +84,4 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI Image Lab") as demo:
80
  api_name="predict"
81
  )
82
 
83
- demo.launch(show_api=True)
 
17
  image_pipe = DiffusionPipeline.from_pretrained(image_model_id)
18
  image_pipe.to(device)
19
 
20
+ def clean_prompt(text, original_user_input):
21
+ forbidden_words = ["4k", "8k", "high res", "high resolution", "hd", "ultra detailed", "masterpiece", "vray", "render"]
22
  for word in forbidden_words:
23
+ text = re.sub(r'\b' + word + r'\b', "", text, flags=re.IGNORECASE)
24
+
25
  text = re.sub(r'\s+', ' ', text).strip()
26
+
27
+ if len(original_user_input.split()) < 4:
28
+ text = f"{original_user_input}, realistic look, centered in the image"
29
+ elif "centered" not in text.lower():
30
+ text += ", centered in the image"
31
+
32
  return text
33
 
34
  def generate_workflow(prompt, width, height, steps):
 
37
  enhanced_results = enhancer_pipe(prompt, max_length=60, num_return_sequences=1)
38
  raw_enhanced = enhanced_results[0]['generated_text']
39
 
40
+ refined_prompt = clean_prompt(raw_enhanced, prompt)
41
 
 
 
 
42
  yield "🎨 Generating (Image generator AI)...", None, refined_prompt
43
 
44
  image = image_pipe(
 
53
 
54
  yield "✅ Ready", image, refined_prompt
55
 
56
+ with gr.Blocks() as demo:
57
  gr.Markdown("# 🎨 AI Image Lab")
58
 
59
  with gr.Row():
 
84
  api_name="predict"
85
  )
86
 
87
+ demo.launch(theme=gr.themes.Soft(), title="AI Image Lab")