Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -106,27 +106,26 @@ async def generate_image(request: ImageRequest, background_tasks: BackgroundTask
|
|
106 |
You are a professional assistant responsible for crafting a clear and visually compelling prompt for an image generation model. Your task is to generate a high-quality prompt for creating both the **main subject** and the **background** of the image.
|
107 |
|
108 |
Image Specifications:
|
109 |
-
- **Subject**: Focus on **{subject}**, highlighting its defining features, expressions, and textures.
|
110 |
-
- **Style**: Emphasize the **{style}**, capturing its key characteristics.
|
111 |
-
- **Background**: Create a background with **{background_details}** that complements and enhances the subject. Ensure it aligns with the color theme and overall composition.
|
112 |
- **Camera and Lighting**:
|
113 |
-
- Lighting: Apply **{lighting_conditions}**, emphasizing depth, highlights, and shadows to accentuate the subject and harmonize the background.
|
114 |
-
- **Framing**: Use a **{framing_style}** to enhance the composition around both the subject and the background.
|
115 |
-
- **Materials**: Highlight textures like **{material_details}**, with realistic details and natural imperfections on the subject and background.
|
116 |
-
- **Key Elements**: Include **{elements}** to enrich the subject’s details and add cohesive elements to the background.
|
117 |
-
- **Color Theme**: Follow the **{color_theme}** to set the mood and tone for the entire scene.
|
118 |
- Negative Prompt: Avoid grainy, blurry, or deformed outputs.
|
119 |
-
- **Text to Include in Image**: Clearly display the text **"{text}"** as part of the composition (e.g., on a card, badge, or banner) attached to the subject in a realistic and contextually appropriate way.
|
120 |
- Write the prompt only in the output. Do not include anything else except the prompt. Do not write Generated Image Prompt: in the output.
|
121 |
-
|
122 |
Chat History:
|
123 |
-
{
|
124 |
-
|
125 |
User Prompt:
|
126 |
-
{user_prompt}
|
127 |
-
|
128 |
-
Generated Image Prompt:
|
129 |
-
|
130 |
"""
|
131 |
refined_prompt = llm.invoke(prompt).content.strip()
|
132 |
collection.insert_one({"session_id": request.chat_id, "role": "user", "content": request.user_prompt})
|
@@ -146,8 +145,8 @@ async def generate_image(request: ImageRequest, background_tasks: BackgroundTask
|
|
146 |
filepath = save_image_locally(img, filename)
|
147 |
return filepath
|
148 |
|
149 |
-
|
150 |
-
background_tasks.add_task(
|
151 |
return {"status": "Processing"}
|
152 |
|
153 |
@app.post("/upscale-image", response_model=dict)
|
|
|
106 |
You are a professional assistant responsible for crafting a clear and visually compelling prompt for an image generation model. Your task is to generate a high-quality prompt for creating both the **main subject** and the **background** of the image.
|
107 |
|
108 |
Image Specifications:
|
109 |
+
- **Subject**: Focus on **{request.subject}**, highlighting its defining features, expressions, and textures.
|
110 |
+
- **Style**: Emphasize the **{request.style}**, capturing its key characteristics.
|
111 |
+
- **Background**: Create a background with **{request.background_details}** that complements and enhances the subject. Ensure it aligns with the color theme and overall composition.
|
112 |
- **Camera and Lighting**:
|
113 |
+
- Lighting: Apply **{request.lighting_conditions}**, emphasizing depth, highlights, and shadows to accentuate the subject and harmonize the background.
|
114 |
+
- **Framing**: Use a **{request.framing_style}** to enhance the composition around both the subject and the background.
|
115 |
+
- **Materials**: Highlight textures like **{request.material_details}**, with realistic details and natural imperfections on the subject and background.
|
116 |
+
- **Key Elements**: Include **{request.elements}** to enrich the subject’s details and add cohesive elements to the background.
|
117 |
+
- **Color Theme**: Follow the **{request.color_theme}** to set the mood and tone for the entire scene.
|
118 |
- Negative Prompt: Avoid grainy, blurry, or deformed outputs.
|
119 |
+
- **Text to Include in Image**: Clearly display the text **"{request.text}"** as part of the composition (e.g., on a card, badge, or banner) attached to the subject in a realistic and contextually appropriate way.
|
120 |
- Write the prompt only in the output. Do not include anything else except the prompt. Do not write Generated Image Prompt: in the output.
|
121 |
+
|
122 |
Chat History:
|
123 |
+
{chat_history}
|
124 |
+
|
125 |
User Prompt:
|
126 |
+
{request.user_prompt}
|
127 |
+
|
128 |
+
Generated Image Prompt:
|
|
|
129 |
"""
|
130 |
refined_prompt = llm.invoke(prompt).content.strip()
|
131 |
collection.insert_one({"session_id": request.chat_id, "role": "user", "content": request.user_prompt})
|
|
|
145 |
filepath = save_image_locally(img, filename)
|
146 |
return filepath
|
147 |
|
148 |
+
# Add the wrapper function to background tasks
|
149 |
+
background_tasks.add_task(lambda: executor.submit(process_request))
|
150 |
return {"status": "Processing"}
|
151 |
|
152 |
@app.post("/upscale-image", response_model=dict)
|