Update main.py
Browse files
main.py
CHANGED
|
@@ -39,23 +39,22 @@ llm = get_llm(LANGCHAIN_API_KEY)
|
|
| 39 |
|
| 40 |
# Define the prompt template for enhancing raw prompts.
|
| 41 |
prompt_template = PromptTemplate.from_template('''
|
| 42 |
-
You are a Prompt Enhancement AI Assistant
|
| 43 |
-
|
| 44 |
-
Enhance the prompt by including:
|
| 45 |
-
-
|
| 46 |
-
-
|
| 47 |
-
-
|
| 48 |
-
-
|
| 49 |
-
-
|
| 50 |
-
- Imagery Elements: (e.g., product shots, icons, background patterns, textures)
|
| 51 |
-
- Lighting & Mood: (e.g., bright, dramatic shadows, soft ambient glow)
|
| 52 |
-
- Contextual Details: (e.g., logo placement, tagline integration, call-to-action placement)
|
| 53 |
- Call-to-Action: include a clear, concise CTA in the poster text (e.g., "Shop Now", "Learn More")
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
| 56 |
{Raw_Prompt}
|
| 57 |
|
| 58 |
-
Enhanced
|
| 59 |
''')
|
| 60 |
|
| 61 |
# Initialize the Google GenAI client.
|
|
@@ -64,11 +63,11 @@ client1 = genai.Client(api_key=GOOGLE_API_KEY)
|
|
| 64 |
# --- Request Models ---
|
| 65 |
|
| 66 |
class EnhancePromptRequest(BaseModel):
|
| 67 |
-
|
| 68 |
|
| 69 |
class GenerateImageRequest(BaseModel):
|
| 70 |
# If both are provided, enhanced_prompt takes priority.
|
| 71 |
-
|
| 72 |
enhanced_prompt: str = None
|
| 73 |
|
| 74 |
class UpdateImageRequest(BaseModel):
|
|
@@ -90,7 +89,7 @@ async def root():
|
|
| 90 |
async def enhance_prompt(request: EnhancePromptRequest):
|
| 91 |
try:
|
| 92 |
# Prepare the prompt using the template.
|
| 93 |
-
formatted_prompt = prompt_template.invoke({"Raw_Prompt": request.
|
| 94 |
# Call the LLM to enhance the prompt.
|
| 95 |
response = llm.invoke(formatted_prompt)
|
| 96 |
# Assume the enhanced prompt is in the response.content.
|
|
@@ -133,7 +132,7 @@ async def generate_image(request: GenerateImageRequest):
|
|
| 133 |
if request.enhanced_prompt:
|
| 134 |
image_prompt = request.enhanced_prompt
|
| 135 |
elif request.raw_prompt:
|
| 136 |
-
image_prompt = request.
|
| 137 |
else:
|
| 138 |
raise HTTPException(status_code=400, detail="Either raw_prompt or enhanced_prompt must be provided.")
|
| 139 |
|
|
|
|
| 39 |
|
| 40 |
# Define the prompt template for enhancing raw prompts.
|
| 41 |
prompt_template = PromptTemplate.from_template('''
|
| 42 |
+
You are a Prompt Enhancement AI Assistant. Your task is to take the user's raw poster image prompt and convert it into a detailed, professional prompt optimized for generating high-quality AI poster.
|
| 43 |
+
|
| 44 |
+
Enhance the prompt by including relevant details such as:
|
| 45 |
+
- Camera specifications (e.g., lens type, aperture, focal length)
|
| 46 |
+
- Lighting setup (e.g., natural light, studio lighting, soft shadows)
|
| 47 |
+
- Camera angle (e.g., top-down, macro, isometric, side view)
|
| 48 |
+
- Background style (e.g., plain white, minimalistic, outdoor, studio backdrop)
|
| 49 |
+
- Scene composition (e.g., centered product, depth of field, reflections)
|
|
|
|
|
|
|
|
|
|
| 50 |
- Call-to-Action: include a clear, concise CTA in the poster text (e.g., "Shop Now", "Learn More")
|
| 51 |
|
| 52 |
+
Focus only on *Poster photography* — do not include humans or models.
|
| 53 |
+
|
| 54 |
+
Raw Prompt:
|
| 55 |
{Raw_Prompt}
|
| 56 |
|
| 57 |
+
Enhanced Prompt:
|
| 58 |
''')
|
| 59 |
|
| 60 |
# Initialize the Google GenAI client.
|
|
|
|
| 63 |
# --- Request Models ---
|
| 64 |
|
| 65 |
class EnhancePromptRequest(BaseModel):
|
| 66 |
+
raw_prompt: str
|
| 67 |
|
| 68 |
class GenerateImageRequest(BaseModel):
|
| 69 |
# If both are provided, enhanced_prompt takes priority.
|
| 70 |
+
raw_prompt: str = None
|
| 71 |
enhanced_prompt: str = None
|
| 72 |
|
| 73 |
class UpdateImageRequest(BaseModel):
|
|
|
|
| 89 |
async def enhance_prompt(request: EnhancePromptRequest):
|
| 90 |
try:
|
| 91 |
# Prepare the prompt using the template.
|
| 92 |
+
formatted_prompt = prompt_template.invoke({"Raw_Prompt": request.raw_prompt})
|
| 93 |
# Call the LLM to enhance the prompt.
|
| 94 |
response = llm.invoke(formatted_prompt)
|
| 95 |
# Assume the enhanced prompt is in the response.content.
|
|
|
|
| 132 |
if request.enhanced_prompt:
|
| 133 |
image_prompt = request.enhanced_prompt
|
| 134 |
elif request.raw_prompt:
|
| 135 |
+
image_prompt = request.raw_prompt
|
| 136 |
else:
|
| 137 |
raise HTTPException(status_code=400, detail="Either raw_prompt or enhanced_prompt must be provided.")
|
| 138 |
|