NikhilJoson commited on
Commit
1192dc4
·
verified ·
1 Parent(s): 9186c7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -30,14 +30,6 @@ class SketchToRealisticFace:
30
  # requires_safety_checker=False
31
  # )
32
 
33
- # Load Realistic LoRA model
34
- # self.pipe = StableDiffusionControlNetPipeline.from_pretrained(
35
- # "SG161222/Realistic_Vision_V6.0_B1_noVAE",
36
- # controlnet=self.controlnet,
37
- # torch_dtype=torch.float16,
38
- # safety_checker=None,
39
- # requires_safety_checker=False
40
- # )
41
  self.pipe = StableDiffusionControlNetPipeline.from_single_file(
42
  "https://huggingface.co/NikhilJoson/Realistic_Vision_V6_B1/blob/main/realisticVisionV60B1_v51HyperVAE.safetensors",
43
  controlnet=self.controlnet,
@@ -106,6 +98,12 @@ print("Loading model... This may take a few minutes.")
106
  generator = SketchToRealisticFace()
107
  print("Model loaded successfully!")
108
 
 
 
 
 
 
 
109
  @spaces.GPU
110
  def generate_face(sketch_image, custom_prompt, seed):
111
  """Wrapper function for Gradio interface"""
@@ -116,7 +114,12 @@ def generate_face(sketch_image, custom_prompt, seed):
116
  # Generate the realistic face
117
  realistic_face, control_image = generator.generate(sketch_image=sketch_image,custom_prompt=custom_prompt,seed=seed_int)
118
 
119
- return realistic_face, control_image
 
 
 
 
 
120
 
121
  except Exception as e:
122
  print(f"Error: {str(e)}")
 
30
  # requires_safety_checker=False
31
  # )
32
 
 
 
 
 
 
 
 
 
33
  self.pipe = StableDiffusionControlNetPipeline.from_single_file(
34
  "https://huggingface.co/NikhilJoson/Realistic_Vision_V6_B1/blob/main/realisticVisionV60B1_v51HyperVAE.safetensors",
35
  controlnet=self.controlnet,
 
98
  generator = SketchToRealisticFace()
99
  print("Model loaded successfully!")
100
 
101
+ def pil_to_base64(image):
102
+ buffer = BytesIO()
103
+ image.save(buffer, format="PNG")
104
+ img_str = base64.b64encode(buffer.getvalue()).decode()
105
+ return f"data:image/png;base64,{img_str}"
106
+
107
  @spaces.GPU
108
  def generate_face(sketch_image, custom_prompt, seed):
109
  """Wrapper function for Gradio interface"""
 
114
  # Generate the realistic face
115
  realistic_face, control_image = generator.generate(sketch_image=sketch_image,custom_prompt=custom_prompt,seed=seed_int)
116
 
117
+ #return realistic_face, control_image
118
+
119
+ # Convert to base64 (uncomment if you want base64 strings)
120
+ realistic_b64 = pil_to_base64(realistic_face)
121
+ control_b64 = pil_to_base64(control_image)
122
+ return realistic_b64, control_b64
123
 
124
  except Exception as e:
125
  print(f"Error: {str(e)}")