Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -18,17 +18,18 @@ from transformers import pipeline
|
|
18 |
from gradio_imageslider import ImageSlider
|
19 |
import numpy as np
|
20 |
import warnings
|
21 |
-
|
|
|
|
|
22 |
|
23 |
huggingface_token = os.getenv("HF_TOKEN")
|
24 |
|
25 |
|
26 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device="cpu")
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
|
31 |
-
token=huggingface_token
|
32 |
)
|
33 |
|
34 |
def augment_prompt(prompt):
|
@@ -38,21 +39,28 @@ def augment_prompt(prompt):
|
|
38 |
|
39 |
system_prompt = """You are an expert at writing detailed image generation prompts.
|
40 |
Enhance the given prompt by adding more descriptive details, artistic style, and technical aspects
|
41 |
-
that would help in generating better images. Keep the core meaning but make it more comprehensive.
|
|
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
response = client.text_generation(
|
47 |
-
full_prompt,
|
48 |
-
max_new_tokens=300,
|
49 |
temperature=0.7,
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
)
|
54 |
|
55 |
-
enhanced_prompt =
|
|
|
|
|
56 |
return enhanced_prompt
|
57 |
except Exception as e:
|
58 |
print(f"Error in prompt augmentation: {str(e)}")
|
|
|
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")
|
26 |
|
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):
|
|
|
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)}")
|