gaur3009 commited on
Commit
21e44c2
·
verified ·
1 Parent(s): 041cdd0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -16
app.py CHANGED
@@ -3,10 +3,12 @@ import requests
3
  from PIL import Image
4
  from io import BytesIO
5
  from tqdm import tqdm
 
6
  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."
@@ -41,12 +43,26 @@ def infer(color_prompt, phone_type_prompt, design_prompt):
41
  else:
42
  raise Exception(f"API Error: {response.status_code}")
43
 
44
- def save_design(image_array):
45
- image = Image.fromarray(image_array)
46
- file_path = "saved_design.png"
 
47
  image.save(file_path)
48
  return f"Design saved as {file_path}!"
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  custom_css = """
51
  body {
52
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
@@ -73,19 +89,10 @@ body::before {
73
  }
74
  """
75
 
 
76
  custom_js = """
77
  <script>
78
  document.addEventListener('DOMContentLoaded', function () {
79
- // Add particles
80
- const particlesContainer = document.createElement('div');
81
- particlesContainer.classList.add('particles');
82
- for (let i = 0; i < 5; i++) {
83
- const particle = document.createElement('div');
84
- particle.classList.add('particle');
85
- particlesContainer.appendChild(particle);
86
- }
87
- document.body.appendChild(particlesContainer);
88
-
89
  // Text-to-speech functionality
90
  function speak(text) {
91
  const synth = window.speechSynthesis;
@@ -102,6 +109,7 @@ document.addEventListener('DOMContentLoaded', function () {
102
  </script>
103
  """
104
 
 
105
  with gr.Blocks(css=custom_css) as interface:
106
  gr.HTML(custom_js)
107
  gr.Markdown("# **AI Phone Cover Designer**")
@@ -110,8 +118,10 @@ with gr.Blocks(css=custom_css) as interface:
110
  # Navigation Tabs
111
  with gr.Tabs():
112
  with gr.Tab("Home"):
113
- gr.Markdown("Welcome to the **AI Phone Cover Designer**! Use the 'Design' tab to start creating custom designs.")
114
-
 
 
115
  with gr.Tab("Design"):
116
  with gr.Row():
117
  with gr.Column(scale=1):
@@ -138,7 +148,7 @@ with gr.Blocks(css=custom_css) as interface:
138
  )
139
 
140
  with gr.Tab("About"):
141
- gr.Markdown("""
142
  ## About AI Phone Cover Maker
143
  The **AI Phone Cover Maker** is a cutting-edge tool designed to help users create personalized phone cover designs quickly and easily.
144
  Powered by AI, it uses advanced image generation techniques to craft unique, high-quality designs for any mobile device.
@@ -151,4 +161,5 @@ with gr.Blocks(css=custom_css) as interface:
151
  Start designing today and bring your creative ideas to life!
152
  """)
153
 
 
154
  interface.launch(debug=True)
 
3
  from PIL import Image
4
  from io import BytesIO
5
  from tqdm import tqdm
6
+ import os
7
  import time
8
 
9
  repo = "artificialguybr/TshirtDesignRedmond-V2"
10
 
11
+ # Generate design based on prompts
12
  def infer(color_prompt, phone_type_prompt, design_prompt):
13
  prompt = (
14
  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
  else:
44
  raise Exception(f"API Error: {response.status_code}")
45
 
46
+ # Save the design
47
+ def save_design(image):
48
+ file_path = "saved_designs/saved_design.png"
49
+ os.makedirs(os.path.dirname(file_path), exist_ok=True)
50
  image.save(file_path)
51
  return f"Design saved as {file_path}!"
52
 
53
+ # Fetch saved designs for display on the Home page
54
+ def fetch_saved_designs():
55
+ saved_designs_dir = "saved_designs"
56
+ if not os.path.exists(saved_designs_dir):
57
+ return ["No saved designs found."]
58
+
59
+ designs = []
60
+ for file_name in os.listdir(saved_designs_dir):
61
+ if file_name.endswith((".png", ".jpg", ".jpeg")):
62
+ designs.append(os.path.join(saved_designs_dir, file_name))
63
+ return designs
64
+
65
+ # Custom CSS for animations
66
  custom_css = """
67
  body {
68
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
 
89
  }
90
  """
91
 
92
+ # JavaScript for text-to-speech and particles
93
  custom_js = """
94
  <script>
95
  document.addEventListener('DOMContentLoaded', function () {
 
 
 
 
 
 
 
 
 
 
96
  // Text-to-speech functionality
97
  function speak(text) {
98
  const synth = window.speechSynthesis;
 
109
  </script>
110
  """
111
 
112
+ # Gradio interface
113
  with gr.Blocks(css=custom_css) as interface:
114
  gr.HTML(custom_js)
115
  gr.Markdown("# **AI Phone Cover Designer**")
 
118
  # Navigation Tabs
119
  with gr.Tabs():
120
  with gr.Tab("Home"):
121
+ gr.Markdown("Welcome to the **AI Phone Cover Designer**! Below are some of your saved designs.")
122
+ saved_images_gallery = gr.Gallery(label="Saved Designs")
123
+ saved_images_gallery.update(value=fetch_saved_designs())
124
+
125
  with gr.Tab("Design"):
126
  with gr.Row():
127
  with gr.Column(scale=1):
 
148
  )
149
 
150
  with gr.Tab("About"):
151
+ gr.Markdown("""
152
  ## About AI Phone Cover Maker
153
  The **AI Phone Cover Maker** is a cutting-edge tool designed to help users create personalized phone cover designs quickly and easily.
154
  Powered by AI, it uses advanced image generation techniques to craft unique, high-quality designs for any mobile device.
 
161
  Start designing today and bring your creative ideas to life!
162
  """)
163
 
164
+ # Launch the app
165
  interface.launch(debug=True)