Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import shutil
|
| 4 |
+
|
| 5 |
+
from eye_lock import process_images_fixed_eyes, create_timelapse
|
| 6 |
+
|
| 7 |
+
def get_images_from_gradio(gradio_input):
|
| 8 |
+
files = []
|
| 9 |
+
if isinstance(gradio_input, list):
|
| 10 |
+
for f in gradio_input:
|
| 11 |
+
if f.lower().endswith((".jpg", ".jpeg", ".png")):
|
| 12 |
+
files.append(f)
|
| 13 |
+
return files
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def gradio_timelapse(images_input,image_duraion=0.1):
|
| 17 |
+
if not images_input:
|
| 18 |
+
return None
|
| 19 |
+
|
| 20 |
+
aligned_folder = "./aligned_fixed_eyes"
|
| 21 |
+
output_folder = "./download"
|
| 22 |
+
|
| 23 |
+
# Clean workspace
|
| 24 |
+
if os.path.exists(aligned_folder):
|
| 25 |
+
shutil.rmtree(aligned_folder)
|
| 26 |
+
os.makedirs(aligned_folder, exist_ok=True)
|
| 27 |
+
|
| 28 |
+
files = get_images_from_gradio(images_input)
|
| 29 |
+
if not files:
|
| 30 |
+
return None
|
| 31 |
+
|
| 32 |
+
process_images_fixed_eyes(files, aligned_folder, canvas_size=1024)
|
| 33 |
+
# for f in files:
|
| 34 |
+
# try:
|
| 35 |
+
# os.remove(f)
|
| 36 |
+
# except Exception as e:
|
| 37 |
+
# pass
|
| 38 |
+
output_video = create_timelapse(aligned_folder, output_folder,fps_in=image_duraion*100)
|
| 39 |
+
return output_video
|
| 40 |
+
def ui():
|
| 41 |
+
custom_css = """.gradio-container { font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif; }"""
|
| 42 |
+
with gr.Blocks(theme=gr.themes.Soft(),css=custom_css) as demo:
|
| 43 |
+
gr.HTML("""
|
| 44 |
+
<div style="text-align: center; margin: 20px auto; max-width: 800px;">
|
| 45 |
+
<h1 style="font-size: 2.5em; margin-bottom: 5px;">👁️ EyeLock Timelapse Generator</h1>
|
| 46 |
+
</div>""")
|
| 47 |
+
with gr.Row():
|
| 48 |
+
with gr.Column():
|
| 49 |
+
images_input = gr.File(
|
| 50 |
+
type="filepath",
|
| 51 |
+
file_count="multiple",
|
| 52 |
+
label="Upload Multiple Images (.jpg, .jpeg, .png only)"
|
| 53 |
+
)
|
| 54 |
+
image_duration = gr.Slider(label="Image Duration (seconds)", minimum=0.01, maximum=1.0, value=0.1, step=0.01, info="Duration each image is shown in the timelapse")
|
| 55 |
+
generate_btn = gr.Button("🚀 Generate Timelapse")
|
| 56 |
+
|
| 57 |
+
with gr.Column():
|
| 58 |
+
output_video = gr.Video(label="Final Timelapse")
|
| 59 |
+
gr.Markdown("### Instructions:")
|
| 60 |
+
gr.Markdown("1. Upload images of faces.")
|
| 61 |
+
gr.Markdown("2. Click 'Generate Timelapse'.")
|
| 62 |
+
gr.Markdown("3. Download the resulting video.")
|
| 63 |
+
gr.Markdown("4. Open any editing app and crop the video according to your use case.")
|
| 64 |
+
generate_btn.click(
|
| 65 |
+
fn=gradio_timelapse,
|
| 66 |
+
inputs=[images_input,image_duration],
|
| 67 |
+
outputs=output_video
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
return demo
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
import click
|
| 74 |
+
@click.command()
|
| 75 |
+
@click.option("--share", is_flag=True, default=False, help="Enable sharing of the interface.")
|
| 76 |
+
@click.option("--debug", is_flag=True, default=False, help="Enable debug mode.")
|
| 77 |
+
def main(share,debug):
|
| 78 |
+
demo = ui()
|
| 79 |
+
print("🚀 Launching Gradio Demo...")
|
| 80 |
+
demo.queue().launch(debug=debug, share=share)
|
| 81 |
+
|
| 82 |
+
if __name__ == "__main__":
|
| 83 |
+
main()
|