Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -184,86 +184,95 @@ def swap_face(source_file, target_file, doFaceEnhancer):
|
|
| 184 |
shutil.rmtree(folder_path)
|
| 185 |
raise gr.Error(f"Face swap failed: {str(e)}")
|
| 186 |
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
|
|
|
| 201 |
|
| 202 |
-
# Gradio interface setup
|
| 203 |
-
title = "Face - Интегратор"
|
| 204 |
-
description = r"""
|
| 205 |
-
The application will save the image history to Hugging Face dataset using the environment variable token.
|
| 206 |
-
Please upload source and target images to begin the face swap process.
|
| 207 |
-
"""
|
| 208 |
-
article = r"""
|
| 209 |
-
<div style="text-align: center; max-width: 650px; margin: 40px auto;">
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
</div>
|
| 215 |
-
"""
|
| 216 |
|
| 217 |
-
# Create Gradio interface with improved layout
|
| 218 |
-
with gr.Blocks(title=title, css=custom_css) as app:
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
)
|
| 236 |
|
| 237 |
-
with gr.
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
)
|
| 243 |
-
|
| 244 |
-
with gr.Row():
|
| 245 |
-
enhance_checkbox = gr.Checkbox(
|
| 246 |
-
label="Применить алгоритм?",
|
| 247 |
-
info="Улучшение качества изображения",
|
| 248 |
-
value=False
|
| 249 |
-
)
|
| 250 |
|
| 251 |
-
|
| 252 |
-
process_btn
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
|
|
|
| 256 |
)
|
|
|
|
|
|
|
| 257 |
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
)
|
| 265 |
-
|
| 266 |
-
gr.Markdown(article)
|
| 267 |
|
| 268 |
-
|
| 269 |
-
|
|
|
|
| 184 |
shutil.rmtree(folder_path)
|
| 185 |
raise gr.Error(f"Face swap failed: {str(e)}")
|
| 186 |
|
| 187 |
+
def create_interface():
|
| 188 |
+
# Create custom style
|
| 189 |
+
custom_css = """
|
| 190 |
+
.container {
|
| 191 |
+
max-width: 1200px;
|
| 192 |
+
margin: auto;
|
| 193 |
+
padding: 20px;
|
| 194 |
+
}
|
| 195 |
+
.output-image {
|
| 196 |
+
min-height: 400px;
|
| 197 |
+
border: 1px solid #ccc;
|
| 198 |
+
border-radius: 8px;
|
| 199 |
+
padding: 10px;
|
| 200 |
+
}
|
| 201 |
+
"""
|
| 202 |
|
| 203 |
+
# Gradio interface setup
|
| 204 |
+
title = "Face - Интегратор"
|
| 205 |
+
description = r"""
|
| 206 |
+
The application will save the image history to Hugging Face dataset using the environment variable token.
|
| 207 |
+
Please upload source and target images to begin the face swap process.
|
| 208 |
+
"""
|
| 209 |
+
article = r"""
|
| 210 |
+
<div style="text-align: center; max-width: 650px; margin: 40px auto;">
|
| 211 |
+
<p>
|
| 212 |
+
This tool performs face swapping with optional enhancement.
|
| 213 |
+
The processed images are automatically saved to the Hugging Face dataset.
|
| 214 |
+
</p>
|
| 215 |
+
</div>
|
| 216 |
+
"""
|
| 217 |
|
| 218 |
+
# Create Gradio interface with improved layout
|
| 219 |
+
with gr.Blocks(title=title, css=custom_css) as app:
|
| 220 |
+
gr.Markdown(f"<h1 style='text-align: center;'>{title}</h1>")
|
| 221 |
+
gr.Markdown(description)
|
| 222 |
+
|
| 223 |
+
with gr.Row():
|
| 224 |
+
with gr.Column(scale=1):
|
| 225 |
+
source_image = gr.Image(
|
| 226 |
+
label="Source Image",
|
| 227 |
+
type="numpy",
|
| 228 |
+
sources=["upload"]
|
| 229 |
+
)
|
| 230 |
+
|
| 231 |
+
with gr.Column(scale=1):
|
| 232 |
+
target_image = gr.Image(
|
| 233 |
+
label="Target Image",
|
| 234 |
+
type="numpy",
|
| 235 |
+
sources=["upload"]
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
with gr.Column(scale=1):
|
| 239 |
+
output_image = gr.Image(
|
| 240 |
+
label="Output Image",
|
| 241 |
+
type="numpy",
|
| 242 |
+
interactive=False,
|
| 243 |
+
elem_classes="output-image"
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
with gr.Row():
|
| 247 |
+
enhance_checkbox = gr.Checkbox(
|
| 248 |
+
label="Применить алгоритм?",
|
| 249 |
+
info="Улучшение качества изображения",
|
| 250 |
+
value=False
|
| 251 |
)
|
| 252 |
|
| 253 |
+
with gr.Row():
|
| 254 |
+
process_btn = gr.Button(
|
| 255 |
+
"Process Face Swap",
|
| 256 |
+
variant="primary",
|
| 257 |
+
size="lg"
|
| 258 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
|
| 260 |
+
# Set up the processing event
|
| 261 |
+
process_btn.click(
|
| 262 |
+
fn=swap_face,
|
| 263 |
+
inputs=[source_image, target_image, enhance_checkbox],
|
| 264 |
+
outputs=output_image,
|
| 265 |
+
api_name="swap_face"
|
| 266 |
)
|
| 267 |
+
|
| 268 |
+
gr.Markdown(article)
|
| 269 |
|
| 270 |
+
return app
|
| 271 |
+
|
| 272 |
+
def main():
|
| 273 |
+
# Create and launch the interface
|
| 274 |
+
app = create_interface()
|
| 275 |
+
app.launch(share=False)
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
+
if __name__ == "__main__":
|
| 278 |
+
main()
|