Vnmrsharma commited on
Commit
aecd8c4
·
verified ·
1 Parent(s): f45478f

Updated: Removed Text Field

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -15,7 +15,7 @@ univin_model = os.environ.get("univin")
15
  client = genai.Client(api_key=api_key)
16
 
17
  CALL_INTERVAL = 2.0 / 10.0 # seconds
18
- dt_lock = Lock()
19
  _last_call_time = 0.0
20
 
21
  def throttle():
@@ -23,7 +23,7 @@ def throttle():
23
  Ensures there's at least CALL_INTERVAL seconds between API calls.
24
  """
25
  global _last_call_time
26
- with dt_lock:
27
  now = time.time()
28
  elapsed = now - _last_call_time
29
  if elapsed < CALL_INTERVAL:
@@ -51,13 +51,14 @@ PROMPT_VARIATIONS = [
51
  ]
52
 
53
  # Detailed prompt variations for different backgrounds/angles
54
- def process_variation(variation, input_image, product_name):
 
55
  # Throttle to respect API rate limit
56
  throttle()
57
 
58
  # Build text + image input
59
  text_input = (
60
- f"Hi, this is a picture of a product. The name of the product is {product_name}.",
61
  variation
62
  )
63
 
@@ -79,19 +80,19 @@ def process_variation(variation, input_image, product_name):
79
  return None
80
 
81
 
82
- def generate_images(input_image, product_name):
83
  """
84
  Generate one image per prompt variation in parallel, respecting rate limits.
85
  """
86
  with concurrent.futures.ThreadPoolExecutor() as executor:
87
  futures = [
88
- executor.submit(process_variation, var, input_image, product_name)
89
  for var in PROMPT_VARIATIONS
90
  ]
91
  return [f.result() for f in futures if f.result()]
92
 
93
  # Gradio UI setup with custom styling
94
- def build_interface():
95
  custom_css = """
96
  #generate-button {
97
  background-color: #4A90E2;
@@ -128,11 +129,6 @@ def build_interface():
128
  input_image = gr.Image(
129
  type="pil", label="Upload Product Image", elem_id="upload-img"
130
  )
131
- product_name = gr.Textbox(
132
- label="Product Name",
133
- placeholder="Enter your product's name here",
134
- elem_id="product-name"
135
- )
136
  generate_button = gr.Button(
137
  "Generate Images", variant="primary", elem_id="generate-button"
138
  )
@@ -141,8 +137,7 @@ def build_interface():
141
  """
142
  **How to Use:**
143
  1. Upload a clear photo of your product.
144
- 2. Enter the product name.
145
- 3. Click **Generate Images** and wait a few moments while images are processed within rate limits.
146
  """
147
  )
148
  gallery = gr.Gallery(
@@ -155,7 +150,7 @@ def build_interface():
155
  )
156
  generate_button.click(
157
  fn=generate_images,
158
- inputs=[input_image, product_name],
159
  outputs=gallery
160
  )
161
  return demo
 
15
  client = genai.Client(api_key=api_key)
16
 
17
  CALL_INTERVAL = 2.0 / 10.0 # seconds
18
+ _dt_lock = Lock()
19
  _last_call_time = 0.0
20
 
21
  def throttle():
 
23
  Ensures there's at least CALL_INTERVAL seconds between API calls.
24
  """
25
  global _last_call_time
26
+ with _dt_lock:
27
  now = time.time()
28
  elapsed = now - _last_call_time
29
  if elapsed < CALL_INTERVAL:
 
51
  ]
52
 
53
  # Detailed prompt variations for different backgrounds/angles
54
+
55
+ def process_variation(variation, input_image):
56
  # Throttle to respect API rate limit
57
  throttle()
58
 
59
  # Build text + image input
60
  text_input = (
61
+ "Hi, this is a picture of a product.",
62
  variation
63
  )
64
 
 
80
  return None
81
 
82
 
83
+ def generate_images(input_image):
84
  """
85
  Generate one image per prompt variation in parallel, respecting rate limits.
86
  """
87
  with concurrent.futures.ThreadPoolExecutor() as executor:
88
  futures = [
89
+ executor.submit(process_variation, var, input_image)
90
  for var in PROMPT_VARIATIONS
91
  ]
92
  return [f.result() for f in futures if f.result()]
93
 
94
  # Gradio UI setup with custom styling
95
+ def build_interface():
96
  custom_css = """
97
  #generate-button {
98
  background-color: #4A90E2;
 
129
  input_image = gr.Image(
130
  type="pil", label="Upload Product Image", elem_id="upload-img"
131
  )
 
 
 
 
 
132
  generate_button = gr.Button(
133
  "Generate Images", variant="primary", elem_id="generate-button"
134
  )
 
137
  """
138
  **How to Use:**
139
  1. Upload a clear photo of your product.
140
+ 2. Click **Generate Images** and wait a few moments while images are processed within rate limits.
 
141
  """
142
  )
143
  gallery = gr.Gallery(
 
150
  )
151
  generate_button.click(
152
  fn=generate_images,
153
+ inputs=[input_image],
154
  outputs=gallery
155
  )
156
  return demo