yashvii commited on
Commit
3286552
·
verified ·
1 Parent(s): 9f0a88a

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. gradio_demo/app.py +18 -46
gradio_demo/app.py CHANGED
@@ -32,22 +32,22 @@ from model_util import load_models_xl, get_torch_device, torch_gc
32
  import os
33
  import requests
34
 
35
- try:
36
- # Send a GET request to the URL
37
- response = requests.get("https://storage.googleapis.com/idfy-gff-public/idfy-gff-public%40idfy-eve-ml-training.iam.gserviceaccount.com.json")
38
 
39
- # Raise an exception if the request was unsuccessful
40
- response.raise_for_status()
41
 
42
- # Save the file to the specified path
43
- with open("serviceaccount.json", 'wb') as file:
44
- file.write(response.content)
45
 
46
- print(f"Service account JSON file successfully downloaded")
47
- os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "serviceaccount.json"
48
 
49
- except requests.exceptions.RequestException as e:
50
- print(f"Failed to download the service account JSON file: {e}")
51
 
52
 
53
 
@@ -273,46 +273,18 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
273
  # return p.replace("{prompt}", positive), n + ' ' + negative
274
 
275
  def store_images(email, gallery1, gallery2, gallery3, gallery4,consent):
 
 
276
  if not consent:
277
  raise gr.Error("Consent not provided")
278
- # galleries = []
279
  for i, img in enumerate([gallery1, gallery2, gallery3, gallery4], start=1):
280
  if isinstance(img, np.ndarray):
281
  img = Image.fromarray(img)
282
  print(f"Gallery {i} type after conversion: {type(img)}")
283
  dest = f'{email}/img{i}.png'
284
- upload_pil_image_to_gcs(img,dest)
285
- # galleries.append(img)
286
- # # Create the images directory if it doesn't exist
287
- # if not os.path.exists('images'):
288
- # os.makedirs('images')
289
-
290
- # # Define image file paths
291
- # image_paths = []
292
- # for i, img in enumerate(galleries, start=1):
293
- # img_path = f'images/{email}_gallery{i}.png'
294
- # img.save(img_path)
295
- # image_paths.append(img_path)
296
-
297
- # # Define the CSV file path
298
- # csv_file_path = 'image_data.csv'
299
-
300
- # # Create a DataFrame for the email and image paths
301
- # df = pd.DataFrame({
302
- # 'email': [email],
303
- # 'img1_path': [image_paths[0]],
304
- # 'img2_path': [image_paths[1]],
305
- # 'img3_path': [image_paths[2]],
306
- # 'img4_path': [image_paths[3]],
307
- # })
308
-
309
- # # Write to CSV (append if the file exists, create a new one if it doesn't)
310
- # if not os.path.isfile(csv_file_path):
311
- # df.to_csv(csv_file_path, index=False)
312
- # else:
313
- # df.to_csv(csv_file_path, mode='a', header=False, index=False)
314
-
315
  gr.Info("Thankyou!! Your avatar is on the way to your inbox")
 
316
 
317
  def add_watermark(image, watermark=logo, opacity=128, position="bottom_right", padding=10):
318
  # Convert NumPy array to PIL Image if needed
@@ -511,7 +483,7 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
511
  gallery3 = gr.Image(label="Generated Images", interactive=False)
512
  gallery4 = gr.Image(label="Generated Images", interactive=False)
513
  email = gr.Textbox(label="Email", info="Enter your email address", value="")
514
- consent = gr.Checkbox(label="I am giving my consent to use my data to share my AI Avtar and IDfy relevant information from time to time")
515
  submit1 = gr.Button("SUBMIT", variant = "primary", elem_id="store-btn")
516
  # with gr.Blocks(css=css) as demo:
517
 
@@ -589,7 +561,7 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
589
  submit1.click(
590
  fn=store_images,
591
  inputs=[email,gallery1,gallery2,gallery3,gallery4,consent],
592
- outputs=None)
593
 
594
 
595
 
 
32
  import os
33
  import requests
34
 
35
+ # try:
36
+ # # Send a GET request to the URL
37
+ # response = requests.get("https://storage.googleapis.com/idfy-gff-public/idfy-gff-public%40idfy-eve-ml-training.iam.gserviceaccount.com.json")
38
 
39
+ # # Raise an exception if the request was unsuccessful
40
+ # response.raise_for_status()
41
 
42
+ # # Save the file to the specified path
43
+ # with open("serviceaccount.json", 'wb') as file:
44
+ # file.write(response.content)
45
 
46
+ # print(f"Service account JSON file successfully downloaded")
47
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "serviceaccount.json"
48
 
49
+ # except requests.exceptions.RequestException as e:
50
+ # print(f"Failed to download the service account JSON file: {e}")
51
 
52
 
53
 
 
273
  # return p.replace("{prompt}", positive), n + ' ' + negative
274
 
275
  def store_images(email, gallery1, gallery2, gallery3, gallery4,consent):
276
+ if not email:
277
+ raise gr.Error("Email Id not provided")
278
  if not consent:
279
  raise gr.Error("Consent not provided")
 
280
  for i, img in enumerate([gallery1, gallery2, gallery3, gallery4], start=1):
281
  if isinstance(img, np.ndarray):
282
  img = Image.fromarray(img)
283
  print(f"Gallery {i} type after conversion: {type(img)}")
284
  dest = f'{email}/img{i}.png'
285
+ upload_pil_image_to_gcs(img,dest)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  gr.Info("Thankyou!! Your avatar is on the way to your inbox")
287
+ return None,None,None,None,None
288
 
289
  def add_watermark(image, watermark=logo, opacity=128, position="bottom_right", padding=10):
290
  # Convert NumPy array to PIL Image if needed
 
483
  gallery3 = gr.Image(label="Generated Images", interactive=False)
484
  gallery4 = gr.Image(label="Generated Images", interactive=False)
485
  email = gr.Textbox(label="Email", info="Enter your email address", value="")
486
+ consent = gr.Checkbox(label="I am giving my consent to use my data to share my AI Avtar and IDfy relevant information from time to time", value=True)
487
  submit1 = gr.Button("SUBMIT", variant = "primary", elem_id="store-btn")
488
  # with gr.Blocks(css=css) as demo:
489
 
 
561
  submit1.click(
562
  fn=store_images,
563
  inputs=[email,gallery1,gallery2,gallery3,gallery4,consent],
564
+ outputs=[face_file,gallery1,gallery2,gallery3,gallery4])
565
 
566
 
567