Spaces:
Running
Running
Download app.py from ritujadebnath/Expression_Change: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/ritujadebnath/Expression_Change/resolve/main/app.py
- Command line
-
hf download hf://spaces/ritujadebnath/Expression_Change/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ritujadebnath/Expression_Change/resolve/main/app.py
1.12 kB
| import gradio as gr | |
| from diffusers import StableDiffusionImg2ImgPipeline | |
| import torch | |
| from PIL import Image | |
| # Load model (CPU fallback) | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| pipe = StableDiffusionImg2ImgPipeline.from_pretrained( | |
| "runwayml/stable-diffusion-v1-5", | |
| torch_dtype=torch.float16 if device == "cuda" else torch.float32 | |
| ).to(device) | |
| def edit_expression(image, prompt): | |
| if image is None or prompt.strip() == "": | |
| return None | |
| final_prompt = f"The same person but {prompt}" | |
| result = pipe( | |
| prompt=final_prompt, | |
| image=image, | |
| strength=0.7, | |
| guidance_scale=7.5 | |
| ).images[0] | |
| return result | |
| iface = gr.Interface( | |
| fn=edit_expression, | |
| inputs=[ | |
| gr.Image(type="pil", label="Upload a face image"), | |
| gr.Textbox(label="Describe the expression change (e.g., 'smiling', 'angry')") | |
| ], | |
| outputs=gr.Image(type="pil", label="Edited Image"), | |
| title="🪄 Face Expression Editor", | |
| description="Upload a face photo and change the expression with a text prompt." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |