Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -18,8 +18,6 @@ from transformers import pipeline
|
|
18 |
from gradio_imageslider import ImageSlider
|
19 |
import numpy as np
|
20 |
import warnings
|
21 |
-
import anthropic # 이 줄 추가
|
22 |
-
|
23 |
|
24 |
|
25 |
huggingface_token = os.getenv("HF_TOKEN")
|
@@ -27,45 +25,8 @@ huggingface_token = os.getenv("HF_TOKEN")
|
|
27 |
|
28 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device="cpu")
|
29 |
|
30 |
-
# Claude 클라이언트 초기화로 대체
|
31 |
-
claude_client = anthropic.Anthropic(
|
32 |
-
api_key=os.getenv("CLAUDE_TOKEN")
|
33 |
-
)
|
34 |
|
35 |
-
def augment_prompt(prompt):
|
36 |
-
try:
|
37 |
-
if not prompt:
|
38 |
-
return "", gr.Warning("Please enter a prompt first")
|
39 |
-
|
40 |
-
system_prompt = """You are an expert at writing detailed image generation prompts.
|
41 |
-
Enhance the given prompt by adding more descriptive details, artistic style, and technical aspects
|
42 |
-
that would help in generating better images. Keep the core meaning but make it more comprehensive.
|
43 |
-
Focus on visual details and artistic elements that can be represented in an image."""
|
44 |
-
|
45 |
-
message = claude_client.messages.create(
|
46 |
-
model="claude-3-sonnet-20240229",
|
47 |
-
max_tokens=300,
|
48 |
-
temperature=0.7,
|
49 |
-
messages=[
|
50 |
-
{
|
51 |
-
"role": "system",
|
52 |
-
"content": system_prompt
|
53 |
-
},
|
54 |
-
{
|
55 |
-
"role": "user",
|
56 |
-
"content": f"Original prompt: {prompt}\nPlease enhance this prompt for image generation."
|
57 |
-
}
|
58 |
-
]
|
59 |
-
)
|
60 |
|
61 |
-
enhanced_prompt = message.content[0].text.strip()
|
62 |
-
print(f"Original prompt: {prompt}")
|
63 |
-
print(f"Enhanced prompt: {enhanced_prompt}")
|
64 |
-
return enhanced_prompt
|
65 |
-
except Exception as e:
|
66 |
-
print(f"Error in prompt augmentation: {str(e)}")
|
67 |
-
return prompt
|
68 |
-
|
69 |
#Load prompts for randomization
|
70 |
df = pd.read_csv('prompts.csv', header=None)
|
71 |
prompt_values = df.values.flatten()
|
@@ -865,38 +826,6 @@ input:focus, textarea:focus {
|
|
865 |
margin: 0 !important; /* auto에서 0으로 변경 */
|
866 |
margin-left: 20px !important; /* 왼쪽 여백 추가 */
|
867 |
}
|
868 |
-
|
869 |
-
.enhance-button, .generate-button {
|
870 |
-
flex: 1 !important;
|
871 |
-
min-width: 120px !important;
|
872 |
-
height: 40px !important;
|
873 |
-
margin: 0 5px !important;
|
874 |
-
}
|
875 |
-
|
876 |
-
.enhance-button {
|
877 |
-
background-color: #6b7280 !important;
|
878 |
-
color: white !important;
|
879 |
-
}
|
880 |
-
|
881 |
-
.enhance-button:hover {
|
882 |
-
background-color: #4b5563 !important;
|
883 |
-
}
|
884 |
-
.generate-button {
|
885 |
-
background-color: #3b82f6 !important;
|
886 |
-
color: white !important;
|
887 |
-
}
|
888 |
-
|
889 |
-
.generate-button:hover {
|
890 |
-
background-color: #2563eb !important;
|
891 |
-
}
|
892 |
-
|
893 |
-
/* 버튼 컨테이너 스타일링 */
|
894 |
-
.button-container {
|
895 |
-
display: flex !important;
|
896 |
-
justify-content: space-between !important;
|
897 |
-
gap: 10px !important;
|
898 |
-
width: 100% !important;
|
899 |
-
}
|
900 |
'''
|
901 |
|
902 |
with gr.Blocks(theme=custom_theme, css=css, delete_cache=(60, 3600)) as app:
|
@@ -928,30 +857,11 @@ with gr.Blocks(theme=custom_theme, css=css, delete_cache=(60, 3600)) as app:
|
|
928 |
|
929 |
with gr.Tab(label="Generate"):
|
930 |
# Prompt and Generate Button
|
931 |
-
# Prompt and Generate Buttons 영역 수정
|
932 |
with gr.Row():
|
933 |
with gr.Column(scale=3):
|
934 |
-
prompt = gr.Textbox(
|
935 |
-
label="Prompt",
|
936 |
-
lines=1,
|
937 |
-
placeholder="Type a prompt after selecting a LoRA"
|
938 |
-
)
|
939 |
with gr.Column(scale=1):
|
940 |
-
|
941 |
-
augment_button = gr.Button(
|
942 |
-
"✨프롬프트 증강",
|
943 |
-
variant="secondary",
|
944 |
-
size="sm",
|
945 |
-
scale=1,
|
946 |
-
elem_classes=["enhance-button"]
|
947 |
-
)
|
948 |
-
generate_button = gr.Button(
|
949 |
-
"🎨생성",
|
950 |
-
variant="primary",
|
951 |
-
size="sm",
|
952 |
-
scale=1,
|
953 |
-
elem_classes=["generate-button"]
|
954 |
-
)
|
955 |
|
956 |
# LoRA Selection Area
|
957 |
with gr.Row(elem_id="loaded_loras"):
|
@@ -1099,21 +1009,13 @@ with gr.Blocks(theme=custom_theme, css=css, delete_cache=(60, 3600)) as app:
|
|
1099 |
selected_indices, lora_scale_1, lora_scale_2, lora_scale_3,
|
1100 |
lora_image_1, lora_image_2, lora_image_3]
|
1101 |
)
|
1102 |
-
# 기존 이벤트 핸들러들 위에 추가
|
1103 |
-
augment_button.click(
|
1104 |
-
fn=augment_prompt,
|
1105 |
-
inputs=[prompt],
|
1106 |
-
outputs=[prompt],
|
1107 |
-
api_name="enhance_prompt"
|
1108 |
-
)
|
1109 |
|
1110 |
-
# 기존 generate 이벤트 핸들러 유지
|
1111 |
gr.on(
|
1112 |
triggers=[generate_button.click, prompt.submit],
|
1113 |
fn=run_lora,
|
1114 |
inputs=[prompt, input_image, image_strength, cfg_scale, steps,
|
1115 |
-
|
1116 |
-
|
1117 |
outputs=[result, seed, progress_bar]
|
1118 |
).then(
|
1119 |
fn=lambda x, history: update_history(x, history) if x is not None else history,
|
@@ -1121,7 +1023,6 @@ with gr.Blocks(theme=custom_theme, css=css, delete_cache=(60, 3600)) as app:
|
|
1121 |
outputs=history_gallery
|
1122 |
)
|
1123 |
|
1124 |
-
|
1125 |
if __name__ == "__main__":
|
1126 |
app.queue(max_size=20)
|
1127 |
app.launch(debug=True)
|
|
|
18 |
from gradio_imageslider import ImageSlider
|
19 |
import numpy as np
|
20 |
import warnings
|
|
|
|
|
21 |
|
22 |
|
23 |
huggingface_token = os.getenv("HF_TOKEN")
|
|
|
25 |
|
26 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device="cpu")
|
27 |
|
|
|
|
|
|
|
|
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
#Load prompts for randomization
|
31 |
df = pd.read_csv('prompts.csv', header=None)
|
32 |
prompt_values = df.values.flatten()
|
|
|
826 |
margin: 0 !important; /* auto에서 0으로 변경 */
|
827 |
margin-left: 20px !important; /* 왼쪽 여백 추가 */
|
828 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
829 |
'''
|
830 |
|
831 |
with gr.Blocks(theme=custom_theme, css=css, delete_cache=(60, 3600)) as app:
|
|
|
857 |
|
858 |
with gr.Tab(label="Generate"):
|
859 |
# Prompt and Generate Button
|
|
|
860 |
with gr.Row():
|
861 |
with gr.Column(scale=3):
|
862 |
+
prompt = gr.Textbox(label="Prompt", lines=1, placeholder="Type a prompt after selecting a LoRA")
|
|
|
|
|
|
|
|
|
863 |
with gr.Column(scale=1):
|
864 |
+
generate_button = gr.Button("Generate", variant="primary", elem_classes=["button_total"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
865 |
|
866 |
# LoRA Selection Area
|
867 |
with gr.Row(elem_id="loaded_loras"):
|
|
|
1009 |
selected_indices, lora_scale_1, lora_scale_2, lora_scale_3,
|
1010 |
lora_image_1, lora_image_2, lora_image_3]
|
1011 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1012 |
|
|
|
1013 |
gr.on(
|
1014 |
triggers=[generate_button.click, prompt.submit],
|
1015 |
fn=run_lora,
|
1016 |
inputs=[prompt, input_image, image_strength, cfg_scale, steps,
|
1017 |
+
selected_indices, lora_scale_1, lora_scale_2, lora_scale_3,
|
1018 |
+
randomize_seed, seed, width, height, loras_state],
|
1019 |
outputs=[result, seed, progress_bar]
|
1020 |
).then(
|
1021 |
fn=lambda x, history: update_history(x, history) if x is not None else history,
|
|
|
1023 |
outputs=history_gallery
|
1024 |
)
|
1025 |
|
|
|
1026 |
if __name__ == "__main__":
|
1027 |
app.queue(max_size=20)
|
1028 |
app.launch(debug=True)
|