Upload 2 files
Browse files- app.py +67 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_client import Client, file
|
| 3 |
+
|
| 4 |
+
# API se connect
|
| 5 |
+
client = Client("https://hardwell-hardwell-face-fusion-light-release.ms.show/")
|
| 6 |
+
|
| 7 |
+
# Face swap function
|
| 8 |
+
def swap_faces(source, target, model, enhancer, blend):
|
| 9 |
+
result = client.predict(
|
| 10 |
+
source_image=file(source),
|
| 11 |
+
target_image=file(target),
|
| 12 |
+
swapper=model,
|
| 13 |
+
enhancer=enhancer,
|
| 14 |
+
enhance_blend=blend,
|
| 15 |
+
reference_face_position=1,
|
| 16 |
+
reference_mode=False,
|
| 17 |
+
expression_factor=0,
|
| 18 |
+
api_name="/swap_face_V2"
|
| 19 |
+
)
|
| 20 |
+
return result
|
| 21 |
+
|
| 22 |
+
# Gradio Blocks with fixed image sizes
|
| 23 |
+
with gr.Blocks(css=".gradio-container {background-color: #f7f7f7; font-family: Arial;} .header-links a {display:inline-block;margin:0 8px;padding:8px 14px;border-radius:8px;text-decoration:none;color:white;font-weight:600;} .yt {background:#ff0000;} .tg {background:#229ED9;} .brand-title{font-size:28px;color:#2c3e50;margin:10px 0 6px 0;}") as demo:
|
| 24 |
+
gr.Markdown(
|
| 25 |
+
"""
|
| 26 |
+
<div style='text-align:center;'>
|
| 27 |
+
<img src="https://drive.google.com/thumbnail?id=1iOZHJ1-zAhYOhqSclo694t35gDH0__A_&sz=w1200" alt="AI Guruji" style="max-width:100%;height:200px;object-fit:contain;border-radius:12px;display:block;margin:0 auto;" />
|
| 28 |
+
<div class='brand-title'>AI Guruji</div>
|
| 29 |
+
<div class='header-links'>
|
| 30 |
+
<a class='yt' href='https://www.youtube.com/@AI_Guruji_97' target='_blank'>YouTube</a>
|
| 31 |
+
<a class='tg' href='https://t.me/ai_guruji_97' target='_blank'>Telegram</a>
|
| 32 |
+
</div>
|
| 33 |
+
<p style='margin-top:10px;color:#4b5563;'>Please be patient, the generation is taking almost 2 minutes to complete.</p>
|
| 34 |
+
</div>
|
| 35 |
+
"""
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
with gr.Row():
|
| 39 |
+
with gr.Column():
|
| 40 |
+
source_img = gr.Image(type="filepath", label="Source Image", height=256, width=256)
|
| 41 |
+
with gr.Column():
|
| 42 |
+
target_img = gr.Image(type="filepath", label="Target Image", height=256, width=256)
|
| 43 |
+
|
| 44 |
+
with gr.Row():
|
| 45 |
+
model_choice = gr.Dropdown(
|
| 46 |
+
choices=["hyperswap_1a_256", "inswapper_128", "inswapper_128_fp16", "blendswap_256"],
|
| 47 |
+
value="hyperswap_1a_256",
|
| 48 |
+
label="Face Swap Model"
|
| 49 |
+
)
|
| 50 |
+
enhancer_choice = gr.Dropdown(
|
| 51 |
+
choices=["gfpgan_1.4", "gpen_bfr_512", "codeformer", "restoreformer_plus_plus", "gpen_bfr_1024"],
|
| 52 |
+
value="gfpgan_1.4",
|
| 53 |
+
label="Face Enhancer"
|
| 54 |
+
)
|
| 55 |
+
blend_choice = gr.Slider(0, 100, value=80, step=5, label="Enhance Blend")
|
| 56 |
+
|
| 57 |
+
swap_btn = gr.Button("🚀 Swap Now", elem_id="swap-btn", variant="primary")
|
| 58 |
+
|
| 59 |
+
output_img = gr.Image(label="Output Image", height=400, width=400)
|
| 60 |
+
|
| 61 |
+
swap_btn.click(
|
| 62 |
+
fn=swap_faces,
|
| 63 |
+
inputs=[source_img, target_img, model_choice, enhancer_choice, blend_choice],
|
| 64 |
+
outputs=output_img
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.44.0
|
| 2 |
+
gradio_client==1.3.0
|