rootglitch commited on
Commit
5216c52
·
1 Parent(s): a57bf8b

Added AI gen code

Browse files
Files changed (2) hide show
  1. app.py +35 -9
  2. requirements.txt +2 -0
app.py CHANGED
@@ -4,8 +4,14 @@ import warnings
4
  import random
5
  import time
6
  import logging
 
 
 
7
  from typing import Dict, List, Tuple, Union, Optional
8
 
 
 
 
9
  # Configure logging
10
  logging.basicConfig(
11
  level=logging.INFO,
@@ -218,12 +224,6 @@ def draw_box(box: torch.Tensor, draw: ImageDraw.Draw, label: Optional[str]) -> N
218
 
219
  def run_grounded_sam(
220
  input_image
221
- # text_prompt: str,
222
- # task_type: str,
223
- # box_threshold: float,
224
- # text_threshold: float,
225
- # iou_threshold: float,
226
- # hq_token_only
227
  ) -> List[Image.Image]:
228
  """Main function to run GroundingDINO and SAM-HQ"""
229
  try:
@@ -328,6 +328,31 @@ def run_grounded_sam(
328
  else:
329
  return [Image.new('RGB', (400, 300), color='gray'), Image.new('RGBA', (400, 300), color=(0, 0, 0, 0))]
330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
 
332
  def create_ui():
333
  """Create Gradio UI for CarViz demo"""
@@ -339,7 +364,7 @@ def create_ui():
339
  with gr.Row():
340
  with gr.Column():
341
  input_image = gr.Image(type="pil", label="image")
342
-
343
  run_button = gr.Button(value='Run')
344
 
345
  with gr.Column():
@@ -351,7 +376,8 @@ def create_ui():
351
  run_button.click(
352
  fn=run_grounded_sam,
353
  inputs=[
354
- input_image
 
355
  ],
356
  outputs=gallery
357
  )
@@ -360,7 +386,7 @@ def create_ui():
360
 
361
 
362
  if __name__ == "__main__":
363
- parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)
364
  parser.add_argument("--debug", action="store_true", help="using debug mode")
365
  parser.add_argument("--share", action="store_true", help="share the app")
366
  parser.add_argument('--no-gradio-queue', action="store_true", help="disable gradio queue")
 
4
  import random
5
  import time
6
  import logging
7
+ import dotenv
8
+ import fal_client
9
+ import requests
10
  from typing import Dict, List, Tuple, Union, Optional
11
 
12
+ dotenv.load_dotenv()
13
+ FAL_KEY = os.getenv("FAL_KEY")
14
+
15
  # Configure logging
16
  logging.basicConfig(
17
  level=logging.INFO,
 
224
 
225
  def run_grounded_sam(
226
  input_image
 
 
 
 
 
 
227
  ) -> List[Image.Image]:
228
  """Main function to run GroundingDINO and SAM-HQ"""
229
  try:
 
328
  else:
329
  return [Image.new('RGB', (400, 300), color='gray'), Image.new('RGBA', (400, 300), color=(0, 0, 0, 0))]
330
 
331
+ def generate_ai_bg(input_img, prompt):
332
+ print(FAL_KEY)
333
+ handler = fal_client.submit(
334
+ "fal-ai/iclight-v2",
335
+ arguments={
336
+ "prompt": prompt,
337
+ "image_url": input_img
338
+ },
339
+ webhook_url="https://optional.webhook.url/for/results",
340
+ )
341
+
342
+ request_id = handler.request_id
343
+
344
+ status = fal_client.status("fal-ai/iclight-v2", request_id, with_logs=True)
345
+
346
+ result = fal_client.result("fal-ai/iclight-v2", request_id)
347
+
348
+ ic_light_img = result['images'][0]['url']
349
+
350
+ return ic_light_img
351
+
352
+ def generate_image(input_img, prompt):
353
+ ai_gen_image = generate_ai_bg(input_img, prompt)
354
+
355
+ return ai_gen_image
356
 
357
  def create_ui():
358
  """Create Gradio UI for CarViz demo"""
 
364
  with gr.Row():
365
  with gr.Column():
366
  input_image = gr.Image(type="pil", label="image")
367
+ prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
368
  run_button = gr.Button(value='Run')
369
 
370
  with gr.Column():
 
376
  run_button.click(
377
  fn=run_grounded_sam,
378
  inputs=[
379
+ input_image,
380
+ prompt
381
  ],
382
  outputs=gallery
383
  )
 
386
 
387
 
388
  if __name__ == "__main__":
389
+ parser = argparse.ArgumentParser("Carviz demo", add_help=True)
390
  parser.add_argument("--debug", action="store_true", help="using debug mode")
391
  parser.add_argument("--share", action="store_true", help="share the app")
392
  parser.add_argument('--no-gradio-queue', action="store_true", help="disable gradio queue")
requirements.txt CHANGED
@@ -19,3 +19,5 @@ torchvision
19
  transformers
20
  yapf
21
  scipy
 
 
 
19
  transformers
20
  yapf
21
  scipy
22
+ dotenv
23
+ fal_client