anteaterho commited on
Commit
e43a89c
β€’
1 Parent(s): 79ae37c

detect korean and change interface

Browse files
Files changed (1) hide show
  1. app.py +39 -21
app.py CHANGED
@@ -71,27 +71,31 @@ def text2img(prompt, negative_prompt, x, y, isRandom, fixedRandom ,num_inference
71
  seed = int(fixedRandom)
72
  generator = torch.manual_seed(seed)
73
 
74
- # Translate prompt with negative prompt
75
- #allPrompt = (translate(prompt +"/"+ negative_prompt).split("/"))
76
  allPrompt = ["",""]
77
- allPrompt[0] = translate_mBart(prompt)
78
- allPrompt[1] = translate_mBart(negative_prompt)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
- print(len(allPrompt))
81
  print("prompt : " + allPrompt[0])
82
  print("negative prompt : " + allPrompt[1])
83
- _prompt = allPrompt[0]
84
- if len(allPrompt) > 1:
85
- _negative_prompt = allPrompt[1]
86
- else:
87
- _negative_prompt = " "
88
 
89
- # Check about it is English
90
- if _prompt.upper() != _prompt.lower():
91
- print(" it is an alphabet")
92
- else:
93
- print(" it is not an alphabet")
94
- _prompt = "traffic sign of stop says SDXL"
95
 
96
  #_negative_prompt = translate(negative_prompt)
97
  image = pipeline(
@@ -99,18 +103,20 @@ def text2img(prompt, negative_prompt, x, y, isRandom, fixedRandom ,num_inference
99
  ).images[0]
100
 
101
  _seed = str(seed)
102
- _prompt = re.sub(r"[^\uAC00-\uD7A30-9a-zA-Z\s]", "", _prompt)
103
  timestamp = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
104
  #image.save( "./output/" + "sdxl_base_" + "_seed_" + _seed+ "_time_" + timestamp +".png")
105
  #image.save("sdxl_prompt_" + "_seed_" + _seed + ".png")
106
  print(seed)
107
 
 
 
108
  if refine:
109
  image = img2img(prompt=_prompt, negative_prompt=_negative_prompt, image=image)
110
 
111
- return image
112
 
113
- return image
114
 
115
 
116
  def img2img(prompt, negative_prompt, image):
@@ -125,9 +131,21 @@ def img2img(prompt, negative_prompt, image):
125
 
126
  demo = gr.Interface(
127
  fn=text2img,
128
- inputs=["text", "text", gr.Slider(0,2048), gr.Slider(0,2048), gr.Checkbox(["random"]), "number", "number", "number", gr.Checkbox(["refine"])],
129
- outputs=["image"],
 
 
 
 
 
 
 
 
 
 
130
  title ="ν•œκΈ€λ‘œ ν•˜λŠ” SDXL",
 
 
131
  )
132
 
133
  demo.launch()
 
71
  seed = int(fixedRandom)
72
  generator = torch.manual_seed(seed)
73
 
74
+ # Check Koran prompts
 
75
  allPrompt = ["",""]
76
+ if prompt.upper() != prompt.lower():
77
+ print("prompt is an alphabet")
78
+ allPrompt[0] = prompt
79
+ else:
80
+ print("prompt is not an alphabet")
81
+ allPrompt[0] = translate_mBart(prompt)
82
+
83
+ if negative_prompt != "":
84
+ if negative_prompt.upper() != negative_prompt.lower():
85
+ print("negative prompt is an alphabet")
86
+ allPrompt[1] = negative_prompt
87
+ else:
88
+ print("negative prompt is not an alphabet")
89
+ allPrompt[1] = translate_mBart(negative_prompt)
90
+ else:
91
+ negative_prompt = ""
92
 
93
+ print("prompts length : "+ str(len(allPrompt)))
94
  print("prompt : " + allPrompt[0])
95
  print("negative prompt : " + allPrompt[1])
 
 
 
 
 
96
 
97
+ _prompt = allPrompt[0]
98
+ _negative_prompt = allPrompt[1]
 
 
 
 
99
 
100
  #_negative_prompt = translate(negative_prompt)
101
  image = pipeline(
 
103
  ).images[0]
104
 
105
  _seed = str(seed)
106
+ #_prompt = re.sub(r"[^\uAC00-\uD7A30-9a-zA-Z\s]", "", _prompt)
107
  timestamp = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
108
  #image.save( "./output/" + "sdxl_base_" + "_seed_" + _seed+ "_time_" + timestamp +".png")
109
  #image.save("sdxl_prompt_" + "_seed_" + _seed + ".png")
110
  print(seed)
111
 
112
+ _info = "prompt : " + _prompt + " / negative prompt : " + _negative_prompt + " / seed : " + _seed + " / refine : " +str(refine) +" / time : " + timestamp
113
+
114
  if refine:
115
  image = img2img(prompt=_prompt, negative_prompt=_negative_prompt, image=image)
116
 
117
+ return image, _info
118
 
119
+ return image, _info
120
 
121
 
122
  def img2img(prompt, negative_prompt, image):
 
131
 
132
  demo = gr.Interface(
133
  fn=text2img,
134
+ inputs=[gr.Text(label=("prompt"), value=""),
135
+ gr.Text(label=("negative prompt"), value=""),
136
+ gr.Slider(128, 2048, value=1024, label="width"),
137
+ gr.Slider(128, 2048, value=1024, label="height"),
138
+ gr.Checkbox(label="auto random seed", value=True),
139
+ gr.Slider(1, 999999, label="fixed random seed"),
140
+ gr.Slider(1, 120, value=20, label="inference steps"),
141
+ gr.Slider(1, 16, value=7, label="guidance scale"),
142
+ gr.Checkbox(["refine"])
143
+ ],
144
+ outputs=[gr.Image(label="generated image"),
145
+ gr.Textbox(label="properties")],
146
  title ="ν•œκΈ€λ‘œ ν•˜λŠ” SDXL",
147
+ #description="ν•œκΈ€λ‘œ ν•˜λŠ” SDXL",
148
+ #article="test"
149
  )
150
 
151
  demo.launch()