Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -7,6 +7,7 @@ import time | |
| 7 |  | 
| 8 | 
             
            repo = "artificialguybr/TshirtDesignRedmond-V2"
         | 
| 9 |  | 
|  | |
| 10 | 
             
            def infer(color_prompt, phone_type_prompt, design_prompt):
         | 
| 11 | 
             
                prompt = (
         | 
| 12 | 
             
                    f"A single vertical {color_prompt} colored {phone_type_prompt} back cover featuring a bold {design_prompt} design on the front, hanging on the plain wall. The soft light and shadows, creating a striking contrast against the minimal background, evoking modern sophistication."
         | 
| @@ -42,20 +43,32 @@ def infer(color_prompt, phone_type_prompt, design_prompt): | |
| 42 | 
             
                        raise Exception(f"API Error: {response.status_code}")
         | 
| 43 |  | 
| 44 |  | 
|  | |
| 45 | 
             
            custom_css = """
         | 
| 46 | 
             
            body {
         | 
| 47 | 
            -
                font-family:  | 
| 48 | 
             
                margin: 0;
         | 
| 49 | 
             
                padding: 0;
         | 
| 50 | 
            -
                 | 
|  | |
| 51 | 
             
            }
         | 
| 52 | 
            -
            . | 
| 53 | 
             
                background-color: #f8f9fa;
         | 
| 54 | 
            -
                 | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 55 | 
             
            }
         | 
| 56 | 
            -
            . | 
| 57 | 
            -
                 | 
| 58 | 
            -
                color: #f8f9fa;
         | 
| 59 | 
             
            }
         | 
| 60 | 
             
            .avatar-container {
         | 
| 61 | 
             
                text-align: center;
         | 
| @@ -77,66 +90,56 @@ body { | |
| 77 | 
             
                0%, 100% { transform: scale(1); }
         | 
| 78 | 
             
                50% { transform: scale(1.05); }
         | 
| 79 | 
             
            }
         | 
| 80 | 
            -
            @keyframes head-move {
         | 
| 81 | 
            -
                0%, 100% { transform: translateX(0); }
         | 
| 82 | 
            -
                50% { transform: translateX(5px); }
         | 
| 83 | 
            -
            }
         | 
| 84 | 
             
            """
         | 
| 85 |  | 
|  | |
| 86 | 
             
            custom_js = """
         | 
| 87 | 
             
            <script>
         | 
| 88 | 
             
            document.addEventListener('DOMContentLoaded', function () {
         | 
| 89 | 
            -
                // Add  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 90 | 
             
                const avatarContainer = document.createElement('div');
         | 
| 91 | 
             
                avatarContainer.classList.add('avatar-container');
         | 
| 92 | 
            -
                
         | 
| 93 | 
            -
                // Add AI avatar image
         | 
| 94 | 
             
                const avatarImg = document.createElement('img');
         | 
| 95 | 
             
                avatarImg.src = 'https://th.bing.com/th/id/OIP.zeeoSeLcH19kuQ1ABNOGCwHaHU?rs=1&pid=ImgDetMain';
         | 
| 96 | 
             
                avatarImg.alt = "AI Assistant Avatar";
         | 
| 97 | 
             
                avatarImg.classList.add('avatar-img');
         | 
| 98 | 
             
                avatarContainer.appendChild(avatarImg);
         | 
| 99 | 
            -
                
         | 
| 100 | 
            -
                // Add Greeting Text
         | 
| 101 | 
            -
                const messageText = document.createElement('h2');
         | 
| 102 | 
             
                const currentHour = new Date().getHours();
         | 
| 103 | 
            -
                 | 
| 104 | 
            -
                 | 
| 105 | 
            -
                else if (currentHour < 18) greeting = "Good Afternoon!";
         | 
| 106 | 
            -
                else greeting = "Good Evening!";
         | 
| 107 | 
            -
                messageText.textContent = greeting + " I'm your AI assistant. Let's design something amazing!";
         | 
| 108 | 
            -
                avatarContainer.appendChild(messageText);
         | 
| 109 | 
            -
             | 
| 110 | 
            -
                // Prepend the avatar container to the body
         | 
| 111 | 
             
                document.body.prepend(avatarContainer);
         | 
| 112 |  | 
| 113 | 
            -
                //  | 
| 114 | 
            -
                function  | 
| 115 | 
             
                    const synth = window.speechSynthesis;
         | 
| 116 | 
             
                    const utterance = new SpeechSynthesisUtterance(text);
         | 
| 117 | 
            -
                    utterance.lang = 'en-US';
         | 
| 118 | 
             
                    synth.speak(utterance);
         | 
| 119 | 
             
                }
         | 
| 120 | 
            -
             | 
| 121 | 
            -
                // Trigger the speech when the output message is updated
         | 
| 122 | 
             
                document.addEventListener('gradio_event:output_update', (event) => {
         | 
| 123 | 
             
                    const outputText = event.detail?.text || '';
         | 
| 124 | 
             
                    if (outputText) {
         | 
| 125 | 
            -
                         | 
| 126 | 
             
                    }
         | 
| 127 | 
             
                });
         | 
| 128 | 
             
            });
         | 
| 129 | 
             
            </script>
         | 
| 130 | 
             
            """
         | 
| 131 |  | 
|  | |
| 132 | 
             
            with gr.Blocks(css=custom_css) as interface:
         | 
| 133 | 
             
                gr.HTML(custom_js)
         | 
| 134 | 
            -
                gr.Markdown(
         | 
| 135 | 
            -
                    """
         | 
| 136 | 
            -
                    # **AI Phone Cover Designer**
         | 
| 137 | 
            -
                    Create custom designs for your brand with AI. Specify color, style, and design details.
         | 
| 138 | 
            -
                    """
         | 
| 139 | 
            -
                )
         | 
| 140 | 
             
                with gr.Row():
         | 
| 141 | 
             
                    with gr.Column(scale=1):
         | 
| 142 | 
             
                        color_prompt = gr.Textbox(label="Color", placeholder="E.g., Red")
         | 
| @@ -148,19 +151,11 @@ with gr.Blocks(css=custom_css) as interface: | |
| 148 | 
             
                        output_image = gr.Image(label="Generated Design")
         | 
| 149 | 
             
                        output_message = gr.Textbox(label="AI Assistant Message", interactive=False)
         | 
| 150 |  | 
| 151 | 
            -
                def update_chatbot(color, phone_type, design):
         | 
| 152 | 
            -
                    return [("User", f"Color: {color}, Mobile: {phone_type}, Design: {design}")]
         | 
| 153 | 
            -
             | 
| 154 | 
             
                generate_button.click(
         | 
| 155 | 
             
                    infer,
         | 
| 156 | 
             
                    inputs=[color_prompt, phone_type_prompt, design_prompt],
         | 
| 157 | 
             
                    outputs=[output_image, output_message],
         | 
| 158 | 
             
                )
         | 
| 159 | 
            -
                generate_button.click(
         | 
| 160 | 
            -
                    update_chatbot,
         | 
| 161 | 
            -
                    inputs=[color_prompt, phone_type_prompt, design_prompt],
         | 
| 162 | 
            -
                    outputs=[chatbot],
         | 
| 163 | 
            -
                )
         | 
| 164 |  | 
| 165 | 
             
            # Launch the app
         | 
| 166 | 
            -
            interface.launch(debug=True)
         | 
|  | |
| 7 |  | 
| 8 | 
             
            repo = "artificialguybr/TshirtDesignRedmond-V2"
         | 
| 9 |  | 
| 10 | 
            +
            # Generate design based on prompts
         | 
| 11 | 
             
            def infer(color_prompt, phone_type_prompt, design_prompt):
         | 
| 12 | 
             
                prompt = (
         | 
| 13 | 
             
                    f"A single vertical {color_prompt} colored {phone_type_prompt} back cover featuring a bold {design_prompt} design on the front, hanging on the plain wall. The soft light and shadows, creating a striking contrast against the minimal background, evoking modern sophistication."
         | 
|  | |
| 43 | 
             
                        raise Exception(f"API Error: {response.status_code}")
         | 
| 44 |  | 
| 45 |  | 
| 46 | 
            +
            # Custom CSS for Apple-like design
         | 
| 47 | 
             
            custom_css = """
         | 
| 48 | 
             
            body {
         | 
| 49 | 
            +
                font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
         | 
| 50 | 
             
                margin: 0;
         | 
| 51 | 
             
                padding: 0;
         | 
| 52 | 
            +
                background: linear-gradient(135deg, #f7f8fa, #dfe2e6);
         | 
| 53 | 
            +
                color: #333;
         | 
| 54 | 
             
            }
         | 
| 55 | 
            +
            .navbar {
         | 
| 56 | 
             
                background-color: #f8f9fa;
         | 
| 57 | 
            +
                padding: 10px 20px;
         | 
| 58 | 
            +
                display: flex;
         | 
| 59 | 
            +
                justify-content: space-between;
         | 
| 60 | 
            +
                align-items: center;
         | 
| 61 | 
            +
                box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
         | 
| 62 | 
            +
            }
         | 
| 63 | 
            +
            .navbar a {
         | 
| 64 | 
            +
                color: #0071e3;
         | 
| 65 | 
            +
                text-decoration: none;
         | 
| 66 | 
            +
                font-weight: 500;
         | 
| 67 | 
            +
                margin: 0 15px;
         | 
| 68 | 
            +
                transition: color 0.3s;
         | 
| 69 | 
             
            }
         | 
| 70 | 
            +
            .navbar a:hover {
         | 
| 71 | 
            +
                color: #0056b3;
         | 
|  | |
| 72 | 
             
            }
         | 
| 73 | 
             
            .avatar-container {
         | 
| 74 | 
             
                text-align: center;
         | 
|  | |
| 90 | 
             
                0%, 100% { transform: scale(1); }
         | 
| 91 | 
             
                50% { transform: scale(1.05); }
         | 
| 92 | 
             
            }
         | 
|  | |
|  | |
|  | |
|  | |
| 93 | 
             
            """
         | 
| 94 |  | 
| 95 | 
            +
            # JavaScript for text-to-speech and animations
         | 
| 96 | 
             
            custom_js = """
         | 
| 97 | 
             
            <script>
         | 
| 98 | 
             
            document.addEventListener('DOMContentLoaded', function () {
         | 
| 99 | 
            +
                // Add navigation bar
         | 
| 100 | 
            +
                const navbar = document.createElement('div');
         | 
| 101 | 
            +
                navbar.classList.add('navbar');
         | 
| 102 | 
            +
                navbar.innerHTML = `
         | 
| 103 | 
            +
                    <a href="#">Home</a>
         | 
| 104 | 
            +
                    <a href="#">Design</a>
         | 
| 105 | 
            +
                    <a href="#">About</a>
         | 
| 106 | 
            +
                `;
         | 
| 107 | 
            +
                document.body.prepend(navbar);
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                // Add AI assistant avatar and greeting
         | 
| 110 | 
             
                const avatarContainer = document.createElement('div');
         | 
| 111 | 
             
                avatarContainer.classList.add('avatar-container');
         | 
|  | |
|  | |
| 112 | 
             
                const avatarImg = document.createElement('img');
         | 
| 113 | 
             
                avatarImg.src = 'https://th.bing.com/th/id/OIP.zeeoSeLcH19kuQ1ABNOGCwHaHU?rs=1&pid=ImgDetMain';
         | 
| 114 | 
             
                avatarImg.alt = "AI Assistant Avatar";
         | 
| 115 | 
             
                avatarImg.classList.add('avatar-img');
         | 
| 116 | 
             
                avatarContainer.appendChild(avatarImg);
         | 
| 117 | 
            +
                const greeting = document.createElement('h2');
         | 
|  | |
|  | |
| 118 | 
             
                const currentHour = new Date().getHours();
         | 
| 119 | 
            +
                greeting.textContent = currentHour < 12 ? "Good Morning!" : currentHour < 18 ? "Good Afternoon!" : "Good Evening!";
         | 
| 120 | 
            +
                avatarContainer.appendChild(greeting);
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 121 | 
             
                document.body.prepend(avatarContainer);
         | 
| 122 |  | 
| 123 | 
            +
                // Text-to-speech functionality
         | 
| 124 | 
            +
                function speak(text) {
         | 
| 125 | 
             
                    const synth = window.speechSynthesis;
         | 
| 126 | 
             
                    const utterance = new SpeechSynthesisUtterance(text);
         | 
|  | |
| 127 | 
             
                    synth.speak(utterance);
         | 
| 128 | 
             
                }
         | 
|  | |
|  | |
| 129 | 
             
                document.addEventListener('gradio_event:output_update', (event) => {
         | 
| 130 | 
             
                    const outputText = event.detail?.text || '';
         | 
| 131 | 
             
                    if (outputText) {
         | 
| 132 | 
            +
                        speak(outputText);
         | 
| 133 | 
             
                    }
         | 
| 134 | 
             
                });
         | 
| 135 | 
             
            });
         | 
| 136 | 
             
            </script>
         | 
| 137 | 
             
            """
         | 
| 138 |  | 
| 139 | 
            +
            # Gradio interface
         | 
| 140 | 
             
            with gr.Blocks(css=custom_css) as interface:
         | 
| 141 | 
             
                gr.HTML(custom_js)
         | 
| 142 | 
            +
                gr.Markdown("# **AI Phone Cover Designer**")
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 143 | 
             
                with gr.Row():
         | 
| 144 | 
             
                    with gr.Column(scale=1):
         | 
| 145 | 
             
                        color_prompt = gr.Textbox(label="Color", placeholder="E.g., Red")
         | 
|  | |
| 151 | 
             
                        output_image = gr.Image(label="Generated Design")
         | 
| 152 | 
             
                        output_message = gr.Textbox(label="AI Assistant Message", interactive=False)
         | 
| 153 |  | 
|  | |
|  | |
|  | |
| 154 | 
             
                generate_button.click(
         | 
| 155 | 
             
                    infer,
         | 
| 156 | 
             
                    inputs=[color_prompt, phone_type_prompt, design_prompt],
         | 
| 157 | 
             
                    outputs=[output_image, output_message],
         | 
| 158 | 
             
                )
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 159 |  | 
| 160 | 
             
            # Launch the app
         | 
| 161 | 
            +
            interface.launch(debug=True)
         |