Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -309,6 +309,46 @@ footer {display: none}
|
|
309 |
}
|
310 |
"""
|
311 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
313 |
gr.HTML("""
|
314 |
<div class="main-title">
|
@@ -319,11 +359,12 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
319 |
|
320 |
with gr.Row():
|
321 |
with gr.Column(scale=1):
|
322 |
-
# 이미지 생성 섹션
|
323 |
gen_prompt = gr.Textbox(
|
324 |
label="Generation Prompt",
|
325 |
placeholder="Enter your image generation prompt..."
|
326 |
)
|
|
|
|
|
327 |
with gr.Row():
|
328 |
gen_width = gr.Slider(512, 1024, 768, step=64, label="Width")
|
329 |
gen_height = gr.Slider(512, 1024, 768, step=64, label="Height")
|
@@ -441,6 +482,17 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
441 |
outputs=output_image
|
442 |
)
|
443 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
demo.queue(max_size=5)
|
445 |
demo.launch(
|
446 |
server_name="0.0.0.0",
|
|
|
309 |
}
|
310 |
"""
|
311 |
|
312 |
+
try:
|
313 |
+
prompt_enhancer = pipeline(
|
314 |
+
"text-generation",
|
315 |
+
model="CohereForAI/c4ai-command-r-plus-08-2024",
|
316 |
+
token=HF_TOKEN
|
317 |
+
)
|
318 |
+
except Exception as e:
|
319 |
+
print(f"Error initializing prompt enhancer: {str(e)}")
|
320 |
+
prompt_enhancer = None
|
321 |
+
|
322 |
+
def enhance_prompt(prompt: str) -> str:
|
323 |
+
"""프롬프트를 애니메이션 스타일로 증강"""
|
324 |
+
try:
|
325 |
+
if prompt_enhancer is None:
|
326 |
+
return prompt
|
327 |
+
|
328 |
+
base_prompt = f"Convert this into a detailed anime-style image prompt: {prompt}"
|
329 |
+
messages = [{"role": "user", "content": base_prompt}]
|
330 |
+
|
331 |
+
response = prompt_enhancer(messages)
|
332 |
+
enhanced = response[0]['generated_text']
|
333 |
+
|
334 |
+
# 기본 품질 향상 프롬프트 추가
|
335 |
+
enhancements = [
|
336 |
+
"masterpiece, best quality, highly detailed",
|
337 |
+
"anime style, animation style",
|
338 |
+
"vibrant colors, perfect lighting",
|
339 |
+
"professional composition",
|
340 |
+
"[trigger]"
|
341 |
+
]
|
342 |
+
|
343 |
+
# 최종 프롬프트 구성
|
344 |
+
final_prompt = f"{enhanced}, {', '.join(enhancements)}"
|
345 |
+
print(f"Enhanced prompt: {final_prompt}")
|
346 |
+
|
347 |
+
return final_prompt
|
348 |
+
except Exception as e:
|
349 |
+
print(f"Prompt enhancement failed: {str(e)}")
|
350 |
+
return prompt
|
351 |
+
|
352 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
353 |
gr.HTML("""
|
354 |
<div class="main-title">
|
|
|
359 |
|
360 |
with gr.Row():
|
361 |
with gr.Column(scale=1):
|
|
|
362 |
gen_prompt = gr.Textbox(
|
363 |
label="Generation Prompt",
|
364 |
placeholder="Enter your image generation prompt..."
|
365 |
)
|
366 |
+
enhance_btn = gr.Button("✨ Enhance Prompt", variant="secondary")
|
367 |
+
|
368 |
with gr.Row():
|
369 |
gen_width = gr.Slider(512, 1024, 768, step=64, label="Width")
|
370 |
gen_height = gr.Slider(512, 1024, 768, step=64, label="Height")
|
|
|
482 |
outputs=output_image
|
483 |
)
|
484 |
|
485 |
+
# 이벤트 바인딩 추가
|
486 |
+
def update_prompt(prompt):
|
487 |
+
enhanced = enhance_prompt(prompt)
|
488 |
+
return enhanced
|
489 |
+
|
490 |
+
enhance_btn.click(
|
491 |
+
fn=update_prompt,
|
492 |
+
inputs=[gen_prompt],
|
493 |
+
outputs=[gen_prompt]
|
494 |
+
)
|
495 |
+
|
496 |
demo.queue(max_size=5)
|
497 |
demo.launch(
|
498 |
server_name="0.0.0.0",
|