Spaces:
Running
on
Zero
Running
on
Zero
Rishi Desai
commited on
Commit
·
9af3c99
1
Parent(s):
ee3c968
init dump for gradio
Browse files- README.md +41 -0
- gradio_demo.py +83 -0
- requirements.txt +3 -1
README.md
CHANGED
@@ -53,3 +53,44 @@ echo "FAL_API_KEY=your_fal_api_key_here" >> .env
|
|
53 |
```
|
54 |
|
55 |
These API keys are required for certain features of the application to work properly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
```
|
54 |
|
55 |
These API keys are required for certain features of the application to work properly.
|
56 |
+
|
57 |
+
# Face Enhancement Gradio Demo
|
58 |
+
|
59 |
+
A web interface for the face enhancement workflow using Gradio.
|
60 |
+
|
61 |
+
## Features
|
62 |
+
|
63 |
+
- Simple web interface for face enhancement
|
64 |
+
- Upload input image and reference face image
|
65 |
+
- Queue system to process jobs sequentially on a single GPU
|
66 |
+
- Approximately 60 seconds processing time per image
|
67 |
+
|
68 |
+
## Setup
|
69 |
+
|
70 |
+
1. Install dependencies:
|
71 |
+
|
72 |
+
```bash
|
73 |
+
pip install -r requirements.txt
|
74 |
+
```
|
75 |
+
|
76 |
+
2. Run the Gradio demo:
|
77 |
+
|
78 |
+
```bash
|
79 |
+
python gradio_demo.py
|
80 |
+
```
|
81 |
+
|
82 |
+
3. Open your browser and go to http://localhost:7860
|
83 |
+
|
84 |
+
## Usage
|
85 |
+
|
86 |
+
1. Upload an input image you want to enhance
|
87 |
+
2. Upload a reference face image
|
88 |
+
3. Click "Enhance Face" to start the process
|
89 |
+
4. Wait approximately 60 seconds for processing
|
90 |
+
5. View the enhanced result in the output panel
|
91 |
+
|
92 |
+
## Notes
|
93 |
+
|
94 |
+
- The demo uses a job queue to ensure only one job runs at a time
|
95 |
+
- Processing takes approximately 60 seconds per image
|
96 |
+
- Temporary files are created during processing and cleaned up afterward
|
gradio_demo.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import tempfile
|
4 |
+
from main import process_face
|
5 |
+
|
6 |
+
def enhance_face_gradio(input_image, ref_image):
|
7 |
+
"""
|
8 |
+
Wrapper function for process_face that works with Gradio.
|
9 |
+
|
10 |
+
Args:
|
11 |
+
input_image: Input image from Gradio
|
12 |
+
ref_image: Reference face image from Gradio
|
13 |
+
|
14 |
+
Returns:
|
15 |
+
str: Path to the enhanced image
|
16 |
+
"""
|
17 |
+
# Create temporary files for input, reference, and output
|
18 |
+
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as input_file, \
|
19 |
+
tempfile.NamedTemporaryFile(suffix=".png", delete=False) as ref_file, \
|
20 |
+
tempfile.NamedTemporaryFile(suffix=".png", delete=False) as output_file:
|
21 |
+
|
22 |
+
input_path = input_file.name
|
23 |
+
ref_path = ref_file.name
|
24 |
+
output_path = output_file.name
|
25 |
+
|
26 |
+
# Save uploaded images to temporary files
|
27 |
+
input_image.save(input_path)
|
28 |
+
ref_image.save(ref_path)
|
29 |
+
|
30 |
+
# Process the face
|
31 |
+
process_face(
|
32 |
+
input_path=input_path,
|
33 |
+
ref_path=ref_path,
|
34 |
+
crop=False,
|
35 |
+
upscale=False,
|
36 |
+
output_path=output_path
|
37 |
+
)
|
38 |
+
|
39 |
+
# Clean up temporary input and reference files
|
40 |
+
os.unlink(input_path)
|
41 |
+
os.unlink(ref_path)
|
42 |
+
|
43 |
+
return output_path
|
44 |
+
|
45 |
+
# Create the Gradio interface
|
46 |
+
with gr.Blocks(title="Face Enhancement Demo") as demo:
|
47 |
+
gr.Markdown("# Face Enhancement Demo")
|
48 |
+
gr.Markdown("Upload an input image and a reference face image to enhance the input.")
|
49 |
+
|
50 |
+
with gr.Row():
|
51 |
+
with gr.Column():
|
52 |
+
input_image = gr.Image(label="Input Image", type="pil")
|
53 |
+
ref_image = gr.Image(label="Reference Face", type="pil")
|
54 |
+
enhance_button = gr.Button("Enhance Face")
|
55 |
+
|
56 |
+
with gr.Column():
|
57 |
+
output_image = gr.Image(label="Enhanced Result")
|
58 |
+
|
59 |
+
enhance_button.click(
|
60 |
+
fn=enhance_face_gradio,
|
61 |
+
inputs=[input_image, ref_image],
|
62 |
+
outputs=output_image,
|
63 |
+
queue=True # Enable queue for sequential processing
|
64 |
+
)
|
65 |
+
|
66 |
+
gr.Markdown("""
|
67 |
+
## Instructions
|
68 |
+
1. Upload an image you want to enhance
|
69 |
+
2. Upload a reference face image
|
70 |
+
3. Click 'Enhance Face' to start the process
|
71 |
+
4. Processing takes about 60 seconds
|
72 |
+
""")
|
73 |
+
|
74 |
+
# Launch the Gradio app with queue
|
75 |
+
if __name__ == "__main__":
|
76 |
+
# Set up queue with max_size=20 and concurrency=1
|
77 |
+
demo.queue(max_size=20) # Configure queue size
|
78 |
+
demo.launch(
|
79 |
+
share=False, # Set to True if you want a public link
|
80 |
+
server_name="0.0.0.0", # Make available on all network interfaces
|
81 |
+
server_port=7860, # Default Gradio port
|
82 |
+
# concurrency_count=1 # Process one job at a time
|
83 |
+
)
|
requirements.txt
CHANGED
@@ -4,4 +4,6 @@ comfy-cli
|
|
4 |
python-dotenv
|
5 |
requests
|
6 |
openai
|
7 |
-
fal-client
|
|
|
|
|
|
4 |
python-dotenv
|
5 |
requests
|
6 |
openai
|
7 |
+
fal-client
|
8 |
+
gradio>=3.50.2
|
9 |
+
pillow>=10.0.0
|