Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
"""
|
2 |
Marketing Image Generator with Gradio MCP Server
|
3 |
-
Professional AI image generation using Google
|
4 |
Deployed on HuggingFace Spaces with built-in MCP server support
|
5 |
"""
|
6 |
|
@@ -606,7 +606,16 @@ def process_generated_image_and_results(api_response_str: str) -> Tuple[Image.Im
|
|
606 |
response_data = json.loads(api_response_str)
|
607 |
|
608 |
if not response_data.get('success', False):
|
609 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
610 |
|
611 |
# Extract image data
|
612 |
image_info = response_data.get('image', {})
|
@@ -720,7 +729,7 @@ def gradio_generate_marketing_image(prompt: str, style: str, max_retries: int, r
|
|
720 |
)
|
721 |
return process_generated_image_and_results(result_json)
|
722 |
except Exception as e:
|
723 |
-
error_message = f"β Error: {str(e)}"
|
724 |
logger.error(error_message)
|
725 |
return None, error_message
|
726 |
|
@@ -765,7 +774,7 @@ with gr.Blocks(title="Marketing Image Generator MCP", theme=gr.themes.Soft()) as
|
|
765 |
)
|
766 |
|
767 |
review_guidelines = gr.Textbox(
|
768 |
-
label="π Marketing
|
769 |
placeholder="e.g., All text must be in English only, focus on professional appearance, ensure brand colors are prominent",
|
770 |
lines=3,
|
771 |
info="Provide specific marketing guidelines for review"
|
@@ -853,7 +862,7 @@ with gr.Blocks(title="Marketing Image Generator MCP", theme=gr.themes.Soft()) as
|
|
853 |
<div style='text-align: center; color: #666; font-size: 0.9rem;'>
|
854 |
<p>π¨ Marketing Image Generator | Gradio MCP Server</p>
|
855 |
<p>Image Generation + Marketing Review + MCP API</p>
|
856 |
-
<p>MCP Endpoint: <code>/gradio_api/mcp/sse</code></p>
|
857 |
</div>
|
858 |
""")
|
859 |
|
|
|
1 |
"""
|
2 |
Marketing Image Generator with Gradio MCP Server
|
3 |
+
Professional AI image generation using Google Imagen3 with marketing review
|
4 |
Deployed on HuggingFace Spaces with built-in MCP server support
|
5 |
"""
|
6 |
|
|
|
606 |
response_data = json.loads(api_response_str)
|
607 |
|
608 |
if not response_data.get('success', False):
|
609 |
+
error_msg = response_data.get('error', 'Unknown error')
|
610 |
+
|
611 |
+
# Add specific documentation links for common errors
|
612 |
+
doc_link = ""
|
613 |
+
if any(brand in error_msg.lower() for brand in ['hsbc', 'bank', 'political', 'timeout', 'stall']):
|
614 |
+
doc_link = "\n\nπ See content restrictions guide: https://huggingface.co/spaces/CognizantAI/marketing-image-generator/blob/main/README.md#content-policy--brand-restrictions"
|
615 |
+
elif 'api' in error_msg.lower() or 'key' in error_msg.lower():
|
616 |
+
doc_link = "\n\nπ See API troubleshooting: https://huggingface.co/spaces/CognizantAI/marketing-image-generator/blob/main/README.md#common-issues"
|
617 |
+
|
618 |
+
return None, f"β Generation failed: {error_msg}{doc_link}"
|
619 |
|
620 |
# Extract image data
|
621 |
image_info = response_data.get('image', {})
|
|
|
729 |
)
|
730 |
return process_generated_image_and_results(result_json)
|
731 |
except Exception as e:
|
732 |
+
error_message = f"β Error: {str(e)}\n\nπ For troubleshooting help, see: https://huggingface.co/spaces/CognizantAI/marketing-image-generator/blob/main/README.md#content-policy--brand-restrictions"
|
733 |
logger.error(error_message)
|
734 |
return None, error_message
|
735 |
|
|
|
774 |
)
|
775 |
|
776 |
review_guidelines = gr.Textbox(
|
777 |
+
label="π Marketing Review Guidelines (Optional)",
|
778 |
placeholder="e.g., All text must be in English only, focus on professional appearance, ensure brand colors are prominent",
|
779 |
lines=3,
|
780 |
info="Provide specific marketing guidelines for review"
|
|
|
862 |
<div style='text-align: center; color: #666; font-size: 0.9rem;'>
|
863 |
<p>π¨ Marketing Image Generator | Gradio MCP Server</p>
|
864 |
<p>Image Generation + Marketing Review + MCP API</p>
|
865 |
+
<p>π <a href="https://huggingface.co/spaces/CognizantAI/marketing-image-generator/blob/main/README.md" target="_blank">Full Documentation & Troubleshooting</a> | MCP Endpoint: <code>/gradio_api/mcp/sse</code></p>
|
866 |
</div>
|
867 |
""")
|
868 |
|