Sony Thomas commited on
Commit
3d5e9d1
Β·
1 Parent(s): d4c8f94

Add app.py

Browse files
Files changed (3) hide show
  1. .gitignore +2 -0
  2. app.py +49 -0
  3. requirements.txt +71 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ env
2
+ ./env
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import StableDiffusionInpaintPipeline
3
+ import torch
4
+ from PIL import Image, ImageDraw
5
+ # Load a pre-trained Stable Diffusion inpainting model
6
+ pipe = StableDiffusionInpaintPipeline.from_pretrained("runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16)
7
+ pipe.to("cuda")
8
+
9
+ # Function to transform mugshot into a professional portrait
10
+ def transform_to_professional(image):
11
+ # Define prompt for a professional portrait
12
+ prompt = "a professional headshot of a person, studio lighting, corporate background, highly detailed, sharp focus"
13
+ negative_prompt = "blurry, low resolution, distorted, messy background"
14
+
15
+ # Resize and center the input image
16
+ image = image.resize((512, 512))
17
+
18
+ # Add a mask (full image editing for simplicity)
19
+ mask = Image.new("L", image.size, 255)
20
+
21
+ # Generate professional portrait
22
+ result = pipe(
23
+ prompt=prompt,
24
+ image=image,
25
+ mask_image=mask,
26
+ num_inference_steps=50,
27
+ guidance_scale=7.5,
28
+ negative_prompt=negative_prompt,
29
+ )
30
+
31
+ # Return the generated image
32
+ return result.images[0]
33
+
34
+ # Gradio Interface
35
+ with gr.Blocks() as demo:
36
+ gr.Markdown("# Mugshot to Professional Headshot Converter")
37
+ gr.Markdown("Upload a mugshot, and we'll transform it into a professional headshot using Stable Diffusion.")
38
+
39
+ with gr.Row():
40
+ with gr.Column():
41
+ input_image = gr.Image(type="pil", label="Upload Mugshot")
42
+ submit_button = gr.Button("Transform")
43
+ with gr.Column():
44
+ output_image = gr.Image(type="pil", label="Professional Headshot")
45
+
46
+ submit_button.click(transform_to_professional, inputs=[input_image], outputs=[output_image])
47
+
48
+ # Launch Gradio Interface
49
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ accelerate==1.1.1
2
+ aiofiles==23.2.1
3
+ annotated-types==0.7.0
4
+ anyio==4.6.2.post1
5
+ argcomplete==3.5.1
6
+ certifi==2024.8.30
7
+ charset-normalizer==3.4.0
8
+ click==8.1.7
9
+ colorama==0.4.6
10
+ diffusers==0.31.0
11
+ fastapi==0.115.5
12
+ ffmpy==0.4.0
13
+ filelock==3.16.1
14
+ fsspec==2024.10.0
15
+ gradio==5.6.0
16
+ gradio_client==1.4.3
17
+ h11==0.14.0
18
+ httpcore==1.0.7
19
+ httpx==0.27.2
20
+ huggingface-hub==0.26.2
21
+ idna==3.10
22
+ importlib_metadata==8.5.0
23
+ Jinja2==3.1.4
24
+ markdown-it-py==3.0.0
25
+ MarkupSafe==2.1.5
26
+ mdurl==0.1.2
27
+ mpmath==1.3.0
28
+ networkx==3.4.2
29
+ numpy==2.1.3
30
+ orjson==3.10.11
31
+ packaging==24.1
32
+ pandas==2.2.3
33
+ pillow==11.0.0
34
+ pipx==1.7.1
35
+ platformdirs==4.3.6
36
+ psutil==6.1.0
37
+ pydantic==2.9.2
38
+ pydantic_core==2.23.4
39
+ pydub==0.25.1
40
+ Pygments==2.18.0
41
+ python-dateutil==2.9.0.post0
42
+ python-multipart==0.0.12
43
+ pytz==2024.2
44
+ PyYAML==6.0.2
45
+ regex==2024.11.6
46
+ requests==2.32.3
47
+ rich==13.9.4
48
+ ruff==0.7.4
49
+ safehttpx==0.1.1
50
+ safetensors==0.4.5
51
+ semantic-version==2.10.0
52
+ setuptools==75.1.0
53
+ shellingham==1.5.4
54
+ six==1.16.0
55
+ sniffio==1.3.1
56
+ starlette==0.41.2
57
+ sympy==1.13.1
58
+ tokenizers==0.20.3
59
+ tomlkit==0.12.0
60
+ torch==2.5.1
61
+ tqdm==4.67.0
62
+ transformers==4.46.2
63
+ typer==0.13.0
64
+ typing_extensions==4.12.2
65
+ tzdata==2024.2
66
+ urllib3==2.2.3
67
+ userpath==1.9.2
68
+ uvicorn==0.32.0
69
+ websockets==12.0
70
+ wheel==0.44.0
71
+ zipp==3.21.0