gaur3009 commited on
Commit
23585ff
·
verified ·
1 Parent(s): 8f0fdc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -81
app.py CHANGED
@@ -7,9 +7,10 @@ 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.")
 
13
  full_prompt = f"{prompt}"
14
 
15
  print("Generating image with prompt:", full_prompt)
@@ -20,7 +21,7 @@ def infer(color_prompt, Phone_type_prompt, design_prompt):
20
  "parameters": {
21
  "negative_prompt": "(worst quality, low quality, lowres, oversaturated, grayscale, bad photo:1.4)",
22
  "num_inference_steps": 30,
23
- "scheduler": "DPMSolverMultistepScheduler"
24
  },
25
  }
26
 
@@ -29,7 +30,8 @@ def infer(color_prompt, Phone_type_prompt, design_prompt):
29
  while True:
30
  response = requests.post(api_url, headers=headers, json=payload)
31
  if response.status_code == 200:
32
- return Image.open(BytesIO(response.content))
 
33
  elif response.status_code == 503:
34
  time.sleep(1)
35
  pbar.update(1)
@@ -55,83 +57,64 @@ body {
55
  background-color: #333;
56
  color: #f8f9fa;
57
  }
58
- .gr-markdown-container {
59
- transition: color 0.3s;
60
- }
61
- .light-mode .gr-markdown-container {
62
- color: #333;
63
- }
64
- .dark-mode .gr-markdown-container {
65
- color: #f8f9fa;
66
- }
67
- textarea, input {
68
- padding: 10px;
69
- border-radius: 8px;
70
- border: 2px solid #ccc;
71
- margin-bottom: 10px;
72
- width: 100%;
73
- }
74
- textarea.dark-mode, input.dark-mode {
75
- background-color: #444;
76
- color: #f8f9fa;
77
- border: 2px solid #555;
78
- }
79
- textarea.light-mode, input.light-mode {
80
- background-color: #fff;
81
- color: #333;
82
- }
83
- .output-image {
84
- max-width: 100%;
85
- border-radius: 12px;
86
- margin-top: 20px;
87
- }
88
  .avatar-container {
89
  text-align: center;
90
  margin-bottom: 20px;
91
  }
92
- .avatar-container img {
93
- border-radius: 50%;
94
  width: 150px;
95
  height: 150px;
96
- box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.3);
97
- animation: bounce 2s infinite;
98
  }
99
- @keyframes bounce {
100
- 0%, 100% {
101
- transform: translateY(0);
102
- }
103
- 50% {
104
- transform: translateY(-10px);
105
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  }
107
  """
108
 
109
  custom_js = """
110
  <script>
111
  document.addEventListener('DOMContentLoaded', function () {
112
- const toggleButton = document.createElement('button');
113
- toggleButton.textContent = 'Toggle Light/Dark Mode';
114
- toggleButton.style.marginBottom = '20px';
115
- toggleButton.onclick = () => {
116
- document.body.classList.toggle('dark-mode');
117
- document.body.classList.toggle('light-mode');
118
- };
119
- document.body.prepend(toggleButton);
120
- document.body.classList.add('light-mode'); // Default to light mode
121
-
122
  // Dynamic Welcome Message with AI avatar speech
123
  const welcomeMessage = document.createElement('div');
124
  welcomeMessage.classList.add('avatar-container');
 
 
125
  const avatarImg = document.createElement('img');
126
- avatarImg.src = 'https://th.bing.com/th/id/OIP.zeeoSeLcH19kuQ1ABNOGCwHaHU?rs=1&pid=ImgDetMain'; // Use a valid AI avatar image URL
127
  avatarImg.alt = "AI Assistant Avatar";
128
- avatarImg.style.width = "150px";
129
- avatarImg.style.height = "150px";
130
- avatarImg.style.borderRadius = "50%";
131
- avatarImg.style.margin = "20px auto";
132
- avatarImg.style.display = "block";
133
  welcomeMessage.appendChild(avatarImg);
134
 
 
135
  const messageText = document.createElement('h2');
136
  const currentHour = new Date().getHours();
137
  let greeting = "Welcome!";
@@ -139,19 +122,10 @@ document.addEventListener('DOMContentLoaded', function () {
139
  else if (currentHour < 18) greeting = "Good Afternoon!";
140
  else greeting = "Good Evening!";
141
  messageText.textContent = greeting + " I'm your AI assistant. Let's design something amazing!";
142
- messageText.style.textAlign = "center";
143
- messageText.style.fontSize = "1.5rem";
144
  welcomeMessage.appendChild(messageText);
145
 
 
146
  document.body.prepend(welcomeMessage);
147
-
148
- // Speech synthesis
149
- const speech = new SpeechSynthesisUtterance();
150
- speech.text = messageText.textContent;
151
- speech.pitch = 1;
152
- speech.rate = 1;
153
- speech.lang = 'en-US';
154
- window.speechSynthesis.speak(speech);
155
  });
156
  </script>
157
  """
@@ -162,19 +136,32 @@ with gr.Blocks(css=custom_css) as interface:
162
  """
163
  # **AI Phone Cover Designer**
164
  Create custom designs for your brand with AI. Specify color, style, and design details.
165
- """,
166
- elem_id="gr-markdown-container"
167
  )
168
- with gr.Row(elem_id="responsive-row"):
169
- with gr.Column(scale=1, min_width=300):
170
- color_prompt = gr.Textbox(label="Color", placeholder="E.g., Red", elem_id="component-1")
171
- Back_cover_prompt = gr.Textbox(label="Mobile type", placeholder="E.g., iPhone, Samsung", elem_id="component-2")
172
- design_prompt = gr.Textbox(label="Design Details", placeholder="E.g., Bold stripes with geometric patterns", elem_id="component-3")
 
173
  generate_button = gr.Button("Generate Design")
174
- with gr.Column(scale=1, min_width=300):
175
- output = gr.Image(label="Generated Design", elem_id="output-image")
 
176
 
177
- generate_button.click(infer, inputs=[color_prompt, Back_cover_prompt, design_prompt], outputs=output)
 
 
 
 
 
 
 
 
 
 
 
 
178
 
179
  # Launch the app
180
  interface.launch(debug=True)
 
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."
13
+ )
14
  full_prompt = f"{prompt}"
15
 
16
  print("Generating image with prompt:", full_prompt)
 
21
  "parameters": {
22
  "negative_prompt": "(worst quality, low quality, lowres, oversaturated, grayscale, bad photo:1.4)",
23
  "num_inference_steps": 30,
24
+ "scheduler": "DPMSolverMultistepScheduler",
25
  },
26
  }
27
 
 
30
  while True:
31
  response = requests.post(api_url, headers=headers, json=payload)
32
  if response.status_code == 200:
33
+ speech_text = f"Your image is generated with the color {color_prompt}, mobile type {phone_type_prompt}, and design {design_prompt}."
34
+ return Image.open(BytesIO(response.content)), speech_text
35
  elif response.status_code == 503:
36
  time.sleep(1)
37
  pbar.update(1)
 
57
  background-color: #333;
58
  color: #f8f9fa;
59
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  .avatar-container {
61
  text-align: center;
62
  margin-bottom: 20px;
63
  }
64
+ .avatar-img {
 
65
  width: 150px;
66
  height: 150px;
67
+ border-radius: 50%;
68
+ animation: blink 3s infinite;
69
  }
70
+ @keyframes blink {
71
+ 0%, 100% { opacity: 1; }
72
+ 50% { opacity: 0.7; }
73
+ }
74
+ /* Neon Button Styling */
75
+ button {
76
+ font-size: 1.2rem;
77
+ padding: 10px 20px;
78
+ border-radius: 5px;
79
+ cursor: pointer;
80
+ border: none;
81
+ color: white;
82
+ background: linear-gradient(90deg, red, orange, yellow, green, cyan, blue, violet);
83
+ background-size: 400%;
84
+ box-shadow: 0 0 10px rgba(255, 255, 255, 0.6),
85
+ 0 0 20px rgba(255, 255, 255, 0.4),
86
+ 0 0 40px rgba(255, 255, 255, 0.2);
87
+ animation: neon-button 2s infinite;
88
+ transition: transform 0.3s;
89
+ }
90
+ button:hover {
91
+ transform: scale(1.1);
92
+ box-shadow: 0 0 20px rgba(255, 255, 255, 0.8),
93
+ 0 0 40px rgba(255, 255, 255, 0.6),
94
+ 0 0 60px rgba(255, 255, 255, 0.4);
95
+ }
96
+ /* Neon Animation */
97
+ @keyframes neon-button {
98
+ 0% { background-position: 0%; }
99
+ 100% { background-position: 400%; }
100
  }
101
  """
102
 
103
  custom_js = """
104
  <script>
105
  document.addEventListener('DOMContentLoaded', function () {
 
 
 
 
 
 
 
 
 
 
106
  // Dynamic Welcome Message with AI avatar speech
107
  const welcomeMessage = document.createElement('div');
108
  welcomeMessage.classList.add('avatar-container');
109
+
110
+ // Avatar Image
111
  const avatarImg = document.createElement('img');
112
+ avatarImg.src = 'https://th.bing.com/th/id/OIP.zeeoSeLcH19kuQ1ABNOGCwHaHU?rs=1&pid=ImgDetMain';
113
  avatarImg.alt = "AI Assistant Avatar";
114
+ avatarImg.classList.add('avatar-img');
 
 
 
 
115
  welcomeMessage.appendChild(avatarImg);
116
 
117
+ // Greeting Text
118
  const messageText = document.createElement('h2');
119
  const currentHour = new Date().getHours();
120
  let greeting = "Welcome!";
 
122
  else if (currentHour < 18) greeting = "Good Afternoon!";
123
  else greeting = "Good Evening!";
124
  messageText.textContent = greeting + " I'm your AI assistant. Let's design something amazing!";
 
 
125
  welcomeMessage.appendChild(messageText);
126
 
127
+ // Add to body
128
  document.body.prepend(welcomeMessage);
 
 
 
 
 
 
 
 
129
  });
130
  </script>
131
  """
 
136
  """
137
  # **AI Phone Cover Designer**
138
  Create custom designs for your brand with AI. Specify color, style, and design details.
139
+ """
 
140
  )
141
+ with gr.Row():
142
+ with gr.Column(scale=1):
143
+ color_prompt = gr.Textbox(label="Color", placeholder="E.g., Red")
144
+ phone_type_prompt = gr.Textbox(label="Mobile type", placeholder="E.g., iPhone, Samsung")
145
+ design_prompt = gr.Textbox(label="Design Details", placeholder="E.g., Bold stripes with geometric patterns")
146
+ chatbot = gr.Chatbot()
147
  generate_button = gr.Button("Generate Design")
148
+ with gr.Column(scale=1):
149
+ output_image = gr.Image(label="Generated Design")
150
+ output_message = gr.Textbox(label="AI Assistant Message", interactive=False)
151
 
152
+ def update_chatbot(color, phone_type, design):
153
+ return [("User", f"Color: {color}, Mobile: {phone_type}, Design: {design}")]
154
+
155
+ generate_button.click(
156
+ infer,
157
+ inputs=[color_prompt, phone_type_prompt, design_prompt],
158
+ outputs=[output_image, output_message],
159
+ )
160
+ generate_button.click(
161
+ update_chatbot,
162
+ inputs=[color_prompt, phone_type_prompt, design_prompt],
163
+ outputs=[chatbot],
164
+ )
165
 
166
  # Launch the app
167
  interface.launch(debug=True)