{"repo": "aaron-official/advanced-image-processing-suite", "files": {"app.py": {"e4da01af5a8d1778864d027078a9c6d8a72b6dd2": {"t": 1785674058.350138, "n": 23187, "h": "8efda7d7afc950de", "c": "import os\nfrom config.settings import (\n OPENAI_API_KEY, ANTHROPIC_API_KEY, REMOVE_BG_API_KEY, DEEPSEEK_API_KEY,\n GRADIO_SERVER_NAME, GRADIO_SERVER_PORT\n)\nfrom config.logging_config import setup_logging\nfrom src.image_processing import ImageProcessor\nfrom src.ai_image_generator import AIImageGenerator\nfrom src.background_removal import BackgroundRemover\nfrom src.image_analysis import ImageAnalysis\nfrom src.custom_filters import apply_custom_filter\nfrom src.resize_crop import resize_crop_image\nimport logging\nimport io\nimport zipfile\nimport tempfile\nfrom PIL import Image\n\nsetup_logging()\nlogger = logging.getLogger(__name__)\n\nimport gradio as gr\n\nSUPPORTED_FORMATS = [\n \"JPEG\", \"JPG\", \"PNG\", \"BMP\", \"TIFF\", \"TIF\", \"WEBP\", \"GIF\", \n \"ICO\", \"EPS\", \"PDF\", \"PSD\", \"SVG\", \"HEIC\", \"AVIF\", \"JXL\"\n]\nENHANCEMENT_OPTIONS = [\n \"AI Super Resolution\", \"Noise Reduction\", \"Color Enhancement\", \"Brightness/Contrast\", \"Sharpening\", \"HDR Effect\", \"Vintage Filter\", \"Black & White\", \"Sepia\", \"Vignette\", \"Blur Background\"\n]\n\nprocessor = ImageProcessor()\nai_generator = AIImageGenerator(openai_key=OPENAI_API_KEY, anthropic_key=ANTHROPIC_API_KEY)\nbg_remover = BackgroundRemover()\n\n# Restore AI_MODELS and BG_REMOVAL_SERVICES constants\nAI_MODELS = {\n \"OpenAI DALL-E 3\": \"dall-e-3\",\n \"OpenAI DALL-E 2\": \"dall-e-2\",\n \"Anthropic Claude (via API)\": \"claude-3-5-sonnet-20241022\",\n \"DeepSeek\": \"deepseek-chat\"\n}\nBG_REMOVAL_SERVICES = {\n \"Remove.bg\": \"removebg\",\n \"Removal.ai\": \"removelai\",\n \"Local rembg\": \"local\",\n \"Clipdrop\": \"clipdrop\"\n}\n\n# Custom CSS for better styling\ncustom_css = \"\"\"\n.gradio-container {\n font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;\n background: #f4f6fb;\n color: #222 !important;\n}\n.tab-nav {\n background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);\n}\n.tab-nav button {\n background: transparent !important;\n border: none !important;\n color: #fff !important;\n font-weight: 600 !important;\n font-size: 1.1rem !important;\n text-shadow: 0 1px 2px rgba(0,0,0,0.15);\n}\n.tab-nav button.selected {\n background: rgba(255,255,255,0.2) !important;\n border-radius: 8px !important;\n}\n.upload-container {\n border: 2px dashed #667eea;\n border-radius: 12px;\n padding: 20px;\n text-align: center;\n background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);\n color: #222 !important;\n font-size: 1.05rem;\n transition: all 0.3s ease;\n}\n.upload-container:hover {\n border-color: #764ba2;\n transform: translateY(-2px);\n box-shadow: 0 8px 25px rgba(102, 126, 234, 0.15);\n}\n.feature-card {\n background: #fff;\n border-radius: 12px;\n padding: 20px;\n box-shadow: 0 4px 15px rgba(0,0,0,0.1);\n margin: 10px 0;\n border-left: 4px solid #667eea;\n color: #222 !important;\n}\n.success-message {\n color: #22c55e;\n font-weight: 600;\n font-size: 1.05rem;\n}\n.error-message {\n color: #ef4444;\n font-weight: 600;\n font-size: 1.05rem;\n}\n.gr-textbox label, .gr-dropdown label, .gr-slider label, .gr-number label, .gr-checkbox label {\n color: #222 !important;\n font-weight: 600;\n font-size: 1.05rem;\n}\n.gr-textbox input, .gr-dropdown select, .gr-slider input, .gr-number input, .gr-checkbox input {\n color: #222 !important;\n background: #f8fafc !important;\n border-radius: 6px !important;\n border: 1px solid #c3cfe2 !important;\n font-size: 1.05rem;\n}\n.gr-button {\n font-size: 1.08rem !important;\n font-weight: 600 !important;\n}\n\"\"\"\n\n# Android icon sizes (density: size in px)\nANDROID_ICON_SIZES = {\n \"mdpi\": 48,\n \"hdpi\": 72,\n \"xhdpi\": 96,\n \"xxhdpi\": 144,\n \"xxxhdpi\": 192,\n}\n\ndef make_android_icons_zip(image: Image.Image) -> str:\n import tempfile\n with tempfile.NamedTemporaryFile(suffix=\".zip\", delete=False) as tmp:\n with zipfile.ZipFile(tmp, mode=\"w\") as zf:\n for density, size in ANDROID_ICON_SIZES.items():\n icon = image.resize((size, size), Image.LANCZOS)\n icon_bytes = io.BytesIO()\n icon.save(icon_bytes, format=\"PNG\")\n icon_bytes.seek(0)\n zf.writestr(f\"ic_launcher_{density}.png\", icon_bytes.read())\n return tmp.name # Return the file path for gr.File\n\n# Main Gradio Interface\nwith gr.Blocks(css=custom_css, title=\"🎨 Advanced Image Processing Suite\", theme=gr.themes.Soft()) as demo:\n \n gr.HTML(\"\"\"\n
\n

🎨 Advanced Image Processing Suite

\n

Professional-grade image processing, AI generation, and enhancement tools

\n
\n \"\"\")\n \n with gr.Tabs() as tabs:\n # Tab 1: Format\n with gr.Tab(\"🖼️ Format\", elem_classes=\"feature-card\"):\n gr.Markdown(\"### Convert images between multiple formats with advanced options\")\n \n with gr.Row():\n with gr.Column(scale=1):\n conv_input = gr.Image(label=\"📎 Upload Image\", type=\"filepath\", elem_classes=\"upload-container\")\n conv_format = gr.Dropdown(\n choices=SUPPORTED_FORMATS, \n value=\"PNG\", \n label=\"🎯 Target Format\"\n )\n conv_quality = gr.Slider(\n minimum=10, maximum=100, value=95, \n label=\"🎛️ Quality (for JPEG/WebP)\", step=5\n )\n conv_btn = gr.Button(\"🚀 Convert Image\", variant=\"primary\")\n \n with gr.Column(scale=1):\n conv_output = gr.File(label=\"📥 Download Converted Image\")\n conv_status = gr.Textbox(label=\"📊 Status\", interactive=False)\n \n conv_btn.click(\n fn=lambda img, fmt, qual: processor.convert_image(img, fmt, qual) if img else (None, \"❌ Please upload an image\"),\n inputs=[conv_input, conv_format, conv_quality],\n outputs=[conv_output, conv_status]\n )\n \n # Tab 2: AI Gen\n with gr.Tab(\"🤖 AI Gen\", elem_classes=\"feature-card\"):\n gr.Markdown(\"### Generate stunning images using state-of-the-art AI models\")\n \n with gr.Row():\n with gr.Column():\n gr.Markdown(\"#### 🔑 API Configuration\")\n openai_key = gr.Textbox(\n label=\"OpenAI API Key\", \n type=\"password\", \n placeholder=\"sk-...\"\n )\n anthropic_key = gr.Textbox(\n label=\"Anthropic API Key\", \n type=\"password\", \n placeholder=\"sk-ant-...\"\n )\n deepseek_key = gr.Textbox(\n label=\"DeepSeek API Key\", \n type=\"password\", \n placeholder=\"sk-...\"\n )\n \n save_keys_btn = gr.Button(\"💾 Save API Keys\", size=\"sm\")\n key_status = gr.Textbox(label=\"🔐 Key Status\", interactive=False)\n \n with gr.Row():\n with gr.Column():\n ai_prompt = gr.Textbox(\n label=\"🎨 Image Prompt\", \n placeholder=\"A serene landscape with mountains and a lake at sunset...\",\n lines=3\n )\n ai_model = gr.Dropdown(\n choices=list(AI_MODELS.keys()),\n value=\"OpenAI DALL-E 3\",\n label=\"🧠 AI Model\"\n )\n ai_size = gr.Dropdown(\n choices=[\"256x256\", \"512x512\", \"1024x1024\", \"1792x1024\", \"1024x1792\"],\n value=\"1024x1024\",\n label=\"📐 Image Size\"\n )\n \n generate_btn = gr.Button(\"✨ Generate Image\", variant=\"primary\")\n \n with gr.Column():\n ai_output = gr.Image(label=\"🖼️ Generated Image\")\n ai_status = gr.Textbox(label=\"📊 Generation Status\", interactive=False)\n \n # API key saving (refactored)\n def save_api_keys(openai, anthropic, deepseek):\n ai_generator.openai_key = openai\n ai_generator.anthropic_key = anthropic\n # DeepSeek can be added to ai_generator if implemented\n saved_keys = []\n if openai:\n saved_keys.append(\"OpenAI\")\n if anthropic:\n saved_keys.append(\"Anthropic\")\n if deepseek:\n saved_keys.append(\"DeepSeek\")\n if saved_keys:\n return f\"✅ Saved keys for: {', '.join(saved_keys)}\"\n return \"❌ No keys provided\"\n\n save_keys_btn.click(\n fn=save_api_keys,\n inputs=[openai_key, anthropic_key, deepseek_key],\n outputs=key_status\n )\n\n # Image generation (fixed: pass API keys directly)\n def generate_image(prompt, model, size, openai, anthropic):\n if not prompt:\n return None, \"❌ Please enter a prompt\"\n if \"OpenAI\" in model:\n model_name = AI_MODELS[model]\n temp_gen = AIImageGenerator(openai_key=openai, anthropic_key=anthropic)\n return temp_gen.generate_image_openai(prompt, model_name, size)\n elif \"Anthropic\" in model:\n temp_gen = AIImageGenerator(openai_key=openai, anthropic_key=anthropic)\n return temp_gen.generate_image_anthropic(prompt)\n else:\n return None, f\"❌ {model} not yet implemented\"\n\n generate_btn.click(\n fn=generate_image,\n inputs=[ai_prompt, ai_model, ai_size, openai_key, anthropic_key],\n outputs=[ai_output, ai_status]\n )\n \n # Tab 3: Enhance\n with gr.Tab(\"✨ Enhance\", elem_classes=\"feature-card\"):\n gr.Markdown(\"### Enhance your images with professional-grade filters and AI\")\n \n with gr.Row():\n with gr.Column():\n enhance_input = gr.Image(label=\"📎 Upload Image to Enhance\", type=\"filepath\")\n enhance_type = gr.Dropdown(\n choices=ENHANCEMENT_OPTIONS,\n value=\"Color Enhancement\",\n label=\"🎭 Enhancement Type\"\n )\n enhance_intensity = gr.Slider(\n minimum=0.1, maximum=2.0, value=1.0, step=0.1,\n label=\"🎛️ Enhancement Intensity\"\n )\n enhance_btn = gr.Button(\"🚀 Enhance Image\", variant=\"primary\")\n \n with gr.Column():\n enhance_output = gr.Image(label=\"✨ Enhanced Image\")\n enhance_status = gr.Textbox(label=\"📊 Enhancement Status\", interactive=False)\n \n enhance_btn.click(\n fn=lambda img, enh_type, intensity: processor.enhance_image(img, enh_type, intensity) if img else (None, \"❌ Please upload an image\"),\n inputs=[enhance_input, enhance_type, enhance_intensity],\n outputs=[enhance_output, enhance_status]\n )\n \n # Tab 4: BG Remove\n with gr.Tab(\"🎭 BG Remove\", elem_classes=\"feature-card\"):\n gr.Markdown(\"### Remove backgrounds instantly with AI-powered tools\")\n \n with gr.Row():\n with gr.Column():\n gr.Markdown(\"#### 🔑 API Keys for Premium Services\")\n removebg_key = gr.Textbox(\n label=\"Remove.bg API Key\", \n type=\"password\", \n placeholder=\"Your Remove.bg API key\"\n )\n save_bg_key_btn = gr.Button(\"💾 Save Remove.bg Key\", size=\"sm\")\n bg_key_status = gr.Textbox(label=\"🔐 API Status\", interactive=False)\n \n with gr.Row():\n with gr.Column():\n bg_input = gr.Image(label=\"📎 Upload Image\", type=\"filepath\")\n bg_service = gr.Dropdown(\n choices=list(BG_REMOVAL_SERVICES.keys()),\n value=\"Local rembg\",\n label=\"🛠️ Background Removal Service\"\n )\n bg_btn = gr.Button(\"🎭 Remove Background\", variant=\"primary\")\n \n with gr.Column():\n bg_output = gr.Image(label=\"🖼️ Result (Transparent Background)\")\n bg_status = gr.Textbox(label=\"📊 Processing Status\", interactive=False)\n \n # Save background removal API key (refactored)\n def save_bg_api_key(key):\n bg_remover.removebg_key = key\n if key:\n return \"✅ Remove.bg API key saved\"\n return \"❌ No key provided\"\n save_bg_key_btn.click(\n fn=save_bg_api_key,\n inputs=removebg_key,\n outputs=bg_key_status\n )\n # Background removal (fixed: pass Remove.bg key directly)\n def remove_bg(img, service, removebg):\n if not img:\n return None, \"❌ Please upload an image\"\n service_key = BG_REMOVAL_SERVICES.get(service, \"local\")\n if service_key == \"local\":\n return bg_remover.remove_local(img)\n elif service_key == \"removebg\":\n temp_remover = BackgroundRemover(removebg_key=removebg)\n return temp_remover.remove_with_removebg(img)\n else:\n return None, f\"❌ {service} not implemented\"\n bg_btn.click(\n fn=remove_bg,\n inputs=[bg_input, bg_service, removebg_key],\n outputs=[bg_output, bg_status]\n )\n \n # Tab 5: Batch\n with gr.Tab(\"📦 Batch\", elem_classes=\"feature-card\"):\n gr.Markdown(\"### Process multiple images simultaneously\")\n \n with gr.Row():\n with gr.Column():\n batch_files = gr.Files(label=\"📎 Upload Multiple Images\", file_types=[\"image\"])\n batch_operation = gr.Dropdown(\n choices=[\"Format Conversion\", \"Enhancement\", \"Background Removal\"],\n value=\"Format Conversion\",\n label=\"🔧 Batch Operation\"\n )\n batch_btn = gr.Button(\"🚀 Process Batch\", variant=\"primary\")\n \n with gr.Column():\n batch_output = gr.Files(label=\"📥 Download Processed Images\")\n batch_status = gr.Textbox(label=\"📊 Batch Status\", interactive=False, lines=5)\n \n # Batch processing (refactored)\n def process_batch(files, operation):\n if not files:\n return None, \"❌ Please upload images for batch processing\"\n results = []\n status_messages = []\n for i, file in enumerate(files):\n try:\n if operation == \"Format Conversion\":\n result, msg = processor.convert_image(file.name, \"PNG\")\n elif operation == \"Enhancement\":\n result, msg = processor.enhance_image(file.name, \"Color Enhancement\")\n elif operation == \"Background Removal\":\n result, msg = bg_remover.remove_local(file.name)\n if result:\n results.append(result)\n status_messages.append(f\"File {i+1}: {msg}\")\n except Exception as e:\n status_messages.append(f\"File {i+1}: ❌ Error - {str(e)}\")\n return results if results else None, \"\\n\".join(status_messages)\n batch_btn.click(\n fn=process_batch,\n inputs=[batch_files, batch_operation],\n outputs=[batch_output, batch_status]\n )\n \n # Tab 6: Tools\n with gr.Tab(\"🔬 Tools\", elem_classes=\"feature-card\"):\n gr.Markdown(\"### Professional image analysis and specialized processing\")\n \n with gr.Tabs():\n with gr.Tab(\"🔍 Image Analysis\"):\n with gr.Row():\n with gr.Column():\n analysis_input = gr.Image(label=\"📎 Upload Image for Analysis\", type=\"filepath\")\n analysis_btn = gr.Button(\"🔬 Analyze Image\", variant=\"primary\")\n \n with gr.Column():\n analysis_output = gr.JSON(label=\"📊 Image Analysis Results\")\n \n # Advanced Tools: Image Analysis (refactored)\n def analyze_image(img_path):\n return ImageAnalysis.analyze_image(img_path)\n analysis_btn.click(\n fn=analyze_image,\n inputs=analysis_input,\n outputs=analysis_output\n )\n \n with gr.Tab(\"🎨 Custom Filters\"):\n with gr.Row():\n with gr.Column():\n filter_input = gr.Image(label=\"📎 Upload Image\", type=\"filepath\")\n \n # Custom filter controls\n brightness = gr.Slider(-100, 100, 0, label=\"☀️ Brightness\")\n contrast = gr.Slider(-100, 100, 0, label=\"🌓 Contrast\")\n saturation = gr.Slider(-100, 100, 0, label=\"🎨 Saturation\")\n hue_shift = gr.Slider(-180, 180, 0, label=\"🌈 Hue Shift\")\n \n apply_filter_btn = gr.Button(\"🎭 Apply Custom Filter\", variant=\"primary\")\n \n with gr.Column():\n filter_output = gr.Image(label=\"🖼️ Filtered Image\")\n filter_status = gr.Textbox(label=\"📊 Filter Status\", interactive=False)\n \n # Advanced Tools: Custom Filters (refactored)\n apply_filter_btn.click(\n fn=apply_custom_filter,\n inputs=[filter_input, brightness, contrast, saturation, hue_shift],\n outputs=[filter_output, filter_status]\n )\n \n with gr.Tab(\"📏 Resize & Crop\"):\n with gr.Row():\n with gr.Column():\n resize_input = gr.Image(label=\"📎 Upload Image\", type=\"filepath\")\n \n resize_mode = gr.Radio(\n choices=[\"Resize\", \"Crop\", \"Smart Crop\", \"Canvas Resize\"],\n value=\"Resize\",\n label=\"🔧 Operation Mode\"\n )\n \n new_width = gr.Number(label=\"📐 Width\", value=800)\n new_height = gr.Number(label=\"📐 Height\", value=600)\n \n maintain_ratio = gr.Checkbox(label=\"🔒 Maintain Aspect Ratio\", value=True)\n resize_quality = gr.Dropdown(\n choices=[\"NEAREST\", \"LANCZOS\", \"BILINEAR\", \"BICUBIC\"],\n value=\"LANCZOS\",\n label=\"🎯 Resize Quality\"\n )\n \n resize_btn = gr.Button(\"📏 Process Image\", variant=\"primary\")\n \n with gr.Column():\n resize_output = gr.Image(label=\"🖼️ Processed Image\")\n resize_status = gr.Textbox(label=\"📊 Processing Status\", interactive=False)\n \n # Advanced Tools: Resize & Crop (refactored)\n resize_btn.click(\n fn=resize_crop_image,\n inputs=[resize_input, resize_mode, new_width, new_height, maintain_ratio, resize_quality],\n outputs=[resize_output, resize_status]\n )\n \n # Tab 7: Android Icons\n with gr.Tab(\"📱 Android Icons\", elem_classes=\"feature-card\"):\n gr.Markdown(\"### Generate all Android app icon sizes and download as a ZIP\")\n android_icon_input = gr.Image(type=\"pil\", label=\"Android Icon Source\")\n android_icon_btn = gr.Button(\"Generate Android Icons\")\n android_icon_zip = gr.File(label=\"Download Icons ZIP\")\n\n def handle_android_icon(image):\n if image is None:\n return None\n return make_android_icons_zip(image)\n\n android_icon_btn.click(\n fn=handle_android_icon,\n inputs=android_icon_input,\n outputs=android_icon_zip\n )\n \n # Footer with additional information\n gr.HTML(\"\"\"\n
\n

🚀 Professional Image Processing Suite

\n
\n
\n 📋 Supported Formats:
\n JPEG, PNG, BMP, TIFF, WEBP, GIF, ICO, EPS, PDF, PSD, SVG, HEIC, AVIF, JXL\n
\n
\n 🤖 AI Services:
\n OpenAI DALL-E 2/3, Anthropic Claude, DeepSeek, Remove.bg, Clipdrop\n
\n
\n ✨ Features:
\n Format Conversion, AI Generation, Enhancement, Background Removal, Batch Processing\n
\n
\n

\n • Made with ❤️ & Gradio — by Aaron 🚀 • \n

\n
\n \"\"\")\n\n\n# Launch configuration\nif __name__ == \"__main__\":\n demo.launch(\n server_name=\"localhost\",\n server_port=7860,\n share=True,\n favicon_path=None,\n pwa=True,\n ssl_verify=False,\n show_api=False\n )"}}}}