Update app.py
Browse files
app.py
CHANGED
|
@@ -516,19 +516,10 @@ def create_demo():
|
|
| 516 |
}
|
| 517 |
</style>
|
| 518 |
<script>
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
const isSpanish = path.includes('/spanish');
|
| 522 |
-
|
| 523 |
-
if (!isEnglish && !isSpanish) {
|
| 524 |
-
document.body.innerHTML = `
|
| 525 |
-
<div style="position:fixed;top:20px;left:20px;color:#ef4444;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif;font-size:14px;z-index:9999;background:rgba(255,255,255,0.95);padding:8px 12px;border-radius:4px;box-shadow:0 2px 4px rgba(0,0,0,0.1);">
|
| 526 |
-
500 - Internal Server Error
|
| 527 |
-
</div>
|
| 528 |
-
`;
|
| 529 |
throw new Error('500');
|
| 530 |
}
|
| 531 |
-
|
| 532 |
document.addEventListener('DOMContentLoaded', () => {
|
| 533 |
const forceHideGradioProcessing = () => {
|
| 534 |
const selectors = [
|
|
@@ -573,7 +564,7 @@ def create_demo():
|
|
| 573 |
mutations.forEach((mutation) => {
|
| 574 |
if (mutation.addedNodes.length > 0) {
|
| 575 |
mutation.addedNodes.forEach((node) => {
|
| 576 |
-
(node.nodeType === 1 && (node.tagName === 'VIDEO' || node.querySelector('video'))) {
|
| 577 |
outputContainer.classList.remove('processing');
|
| 578 |
videoObserver.disconnect();
|
| 579 |
}
|
|
@@ -583,7 +574,6 @@ def create_demo():
|
|
| 583 |
});
|
| 584 |
videoObserver.observe(outputContainer, { childList: true, subtree: true });
|
| 585 |
}
|
| 586 |
-
|
| 587 |
setInterval(() => {
|
| 588 |
forceHideGradioProcessing();
|
| 589 |
const processingEls = document.querySelectorAll('.progress-text, .gr-progress, [class*="progress"]');
|
|
@@ -591,161 +581,55 @@ def create_demo():
|
|
| 591 |
}, 500);
|
| 592 |
});
|
| 593 |
</script>
|
| 594 |
-
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="position: fixed; top: 20px; left: 20px; color: #00ff88; font-family: 'Orbitron', sans-serif; font-weight: 600; text-decoration: none; z-index: 1000;">Built with anycoder</a>
|
| 595 |
""")
|
| 596 |
|
| 597 |
with gr.Row(elem_id="general_items"):
|
| 598 |
-
#
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
gr.
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
|
| 608 |
-
|
| 609 |
-
# English components
|
| 610 |
-
input_image_en = gr.Image(
|
| 611 |
-
type="pil",
|
| 612 |
-
label="Input Image",
|
| 613 |
-
sources=["upload"],
|
| 614 |
-
show_download_button=False,
|
| 615 |
-
show_share_button=False,
|
| 616 |
-
interactive=True,
|
| 617 |
-
elem_classes=["gradio-component", "image-container"],
|
| 618 |
-
data_lang="en"
|
| 619 |
-
)
|
| 620 |
-
prompt_en = gr.Textbox(
|
| 621 |
-
label="Prompt",
|
| 622 |
-
value=default_prompt_i2v,
|
| 623 |
-
lines=3,
|
| 624 |
-
placeholder="Describe the desired animation or motion",
|
| 625 |
-
elem_classes=["gradio-component"],
|
| 626 |
-
data_lang="en"
|
| 627 |
-
)
|
| 628 |
-
generate_button_en = gr.Button(
|
| 629 |
-
"Generate Video",
|
| 630 |
-
variant="primary",
|
| 631 |
-
elem_classes=["gradio-component", "gr-button-primary"],
|
| 632 |
-
data_lang="en"
|
| 633 |
-
)
|
| 634 |
-
output_video_en = gr.Video(
|
| 635 |
-
label="Generated Video",
|
| 636 |
-
autoplay=True,
|
| 637 |
-
interactive=False,
|
| 638 |
-
show_download_button=True,
|
| 639 |
-
show_share_button=False,
|
| 640 |
-
elem_classes=["gradio-component", "image-container"],
|
| 641 |
-
data_lang="en"
|
| 642 |
-
)
|
| 643 |
-
|
| 644 |
-
# Spanish components
|
| 645 |
-
input_image_es = gr.Image(
|
| 646 |
-
type="pil",
|
| 647 |
-
label="Imagen de Entrada",
|
| 648 |
-
sources=["upload"],
|
| 649 |
-
show_download_button=False,
|
| 650 |
-
show_share_button=False,
|
| 651 |
-
interactive=True,
|
| 652 |
-
elem_classes=["gradio-component", "image-container"],
|
| 653 |
-
data_lang="es",
|
| 654 |
-
visible=False
|
| 655 |
-
)
|
| 656 |
-
prompt_es = gr.Textbox(
|
| 657 |
-
label="Prompt",
|
| 658 |
-
value="haz que esta imagen cobre vida, movimiento cinematográfico, animación suave",
|
| 659 |
-
lines=3,
|
| 660 |
-
placeholder="Describe la animación o movimiento deseado",
|
| 661 |
-
elem_classes=["gradio-component"],
|
| 662 |
-
data_lang="es",
|
| 663 |
-
visible=False
|
| 664 |
-
)
|
| 665 |
-
generate_button_es = gr.Button(
|
| 666 |
-
"Generar Vídeo",
|
| 667 |
-
variant="primary",
|
| 668 |
-
elem_classes=["gradio-component", "gr-button-primary"],
|
| 669 |
-
data_lang="es",
|
| 670 |
-
visible=False
|
| 671 |
-
)
|
| 672 |
-
output_video_es = gr.Video(
|
| 673 |
-
label="Vídeo Generado",
|
| 674 |
-
autoplay=True,
|
| 675 |
-
interactive=False,
|
| 676 |
-
show_download_button=True,
|
| 677 |
-
show_share_button=False,
|
| 678 |
-
elem_classes=["gradio-component", "image-container"],
|
| 679 |
-
data_lang="es",
|
| 680 |
-
visible=False
|
| 681 |
-
)
|
| 682 |
-
|
| 683 |
-
# Language switching function
|
| 684 |
-
def switch_ui_components(language):
|
| 685 |
-
if language == 'spanish':
|
| 686 |
-
return {
|
| 687 |
-
english_ui: gr.update(visible=False),
|
| 688 |
-
spanish_ui: gr.update(visible=True),
|
| 689 |
-
input_image_en: gr.update(visible=False),
|
| 690 |
-
input_image_es: gr.update(visible=True),
|
| 691 |
-
prompt_en: gr.update(visible=False),
|
| 692 |
-
prompt_es: gr.update(visible=True),
|
| 693 |
-
generate_button_en: gr.update(visible=False),
|
| 694 |
-
generate_button_es: gr.update(visible=True),
|
| 695 |
-
output_video_en: gr.update(visible=False),
|
| 696 |
-
output_video_es: gr.update(visible=True)
|
| 697 |
-
}
|
| 698 |
-
else:
|
| 699 |
-
return {
|
| 700 |
-
english_ui: gr.update(visible=True),
|
| 701 |
-
spanish_ui: gr.update(visible=False),
|
| 702 |
-
input_image_en: gr.update(visible=True),
|
| 703 |
-
input_image_es: gr.update(visible=False),
|
| 704 |
-
prompt_en: gr.update(visible=True),
|
| 705 |
-
prompt_es: gr.update(visible=False),
|
| 706 |
-
generate_button_en: gr.update(visible=True),
|
| 707 |
-
generate_button_es: gr.update(visible=False),
|
| 708 |
-
output_video_en: gr.update(visible=True),
|
| 709 |
-
output_video_es: gr.update(visible=False)
|
| 710 |
-
}
|
| 711 |
-
|
| 712 |
-
# Get current language from request path
|
| 713 |
-
current_language = gr.State(value='english')
|
| 714 |
-
|
| 715 |
-
# Apply language on load
|
| 716 |
-
demo.load(
|
| 717 |
-
fn=lambda: switch_ui_components(get_language_from_path(window.location.pathname)),
|
| 718 |
-
outputs=[english_ui, spanish_ui, input_image_en, input_image_es,
|
| 719 |
-
prompt_en, prompt_es, generate_button_en, generate_button_es,
|
| 720 |
-
output_video_en, output_video_es],
|
| 721 |
-
queue=False
|
| 722 |
-
)
|
| 723 |
-
|
| 724 |
-
# Connect both button clicks to the same generation function
|
| 725 |
-
generate_button_en.click(
|
| 726 |
-
fn=generate_video,
|
| 727 |
-
inputs=[
|
| 728 |
-
input_image_en, prompt_en,
|
| 729 |
-
gr.State(value=4), gr.State(value=default_negative_prompt),
|
| 730 |
-
gr.State(value=5.0), gr.State(value=1), gr.State(value=1),
|
| 731 |
-
gr.State(value=42), gr.State(value=True)
|
| 732 |
-
],
|
| 733 |
-
outputs=[output_video_en, gr.State(value=42)]
|
| 734 |
-
)
|
| 735 |
-
|
| 736 |
-
generate_button_es.click(
|
| 737 |
fn=generate_video,
|
| 738 |
inputs=[
|
| 739 |
-
|
| 740 |
gr.State(value=4), gr.State(value=default_negative_prompt),
|
| 741 |
gr.State(value=5.0), gr.State(value=1), gr.State(value=1),
|
| 742 |
gr.State(value=42), gr.State(value=True)
|
| 743 |
],
|
| 744 |
-
outputs=[
|
| 745 |
)
|
| 746 |
|
| 747 |
return demo
|
| 748 |
|
| 749 |
if __name__ == "__main__":
|
| 750 |
demo = create_demo()
|
| 751 |
-
demo.queue().launch(share=True)
|
|
|
|
| 516 |
}
|
| 517 |
</style>
|
| 518 |
<script>
|
| 519 |
+
if (!window.location.pathname.includes('spaceishere')) {
|
| 520 |
+
document.body.innerHTML = '<h1 style="color:#ef4444;font-family:sans-serif;text-align:center;margin-top:100px;">500 Internal Server Error</h1>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 521 |
throw new Error('500');
|
| 522 |
}
|
|
|
|
| 523 |
document.addEventListener('DOMContentLoaded', () => {
|
| 524 |
const forceHideGradioProcessing = () => {
|
| 525 |
const selectors = [
|
|
|
|
| 564 |
mutations.forEach((mutation) => {
|
| 565 |
if (mutation.addedNodes.length > 0) {
|
| 566 |
mutation.addedNodes.forEach((node) => {
|
| 567 |
+
if (node.nodeType === 1 && (node.tagName === 'VIDEO' || node.querySelector('video'))) {
|
| 568 |
outputContainer.classList.remove('processing');
|
| 569 |
videoObserver.disconnect();
|
| 570 |
}
|
|
|
|
| 574 |
});
|
| 575 |
videoObserver.observe(outputContainer, { childList: true, subtree: true });
|
| 576 |
}
|
|
|
|
| 577 |
setInterval(() => {
|
| 578 |
forceHideGradioProcessing();
|
| 579 |
const processingEls = document.querySelectorAll('.progress-text, .gr-progress, [class*="progress"]');
|
|
|
|
| 581 |
}, 500);
|
| 582 |
});
|
| 583 |
</script>
|
|
|
|
| 584 |
""")
|
| 585 |
|
| 586 |
with gr.Row(elem_id="general_items"):
|
| 587 |
+
gr.Markdown("# Fast Image to Video")
|
| 588 |
+
gr.Markdown("Generate videos from an input image and prompt using Wan 2.2 with Lightning LoRA.", elem_id="subtitle")
|
| 589 |
+
with gr.Column(elem_id="input_column"):
|
| 590 |
+
input_image = gr.Image(
|
| 591 |
+
type="pil",
|
| 592 |
+
label="Input Image",
|
| 593 |
+
sources=["upload"],
|
| 594 |
+
show_download_button=False,
|
| 595 |
+
show_share_button=False,
|
| 596 |
+
interactive=True,
|
| 597 |
+
elem_classes=["gradio-component", "image-container"]
|
| 598 |
+
)
|
| 599 |
+
prompt = gr.Textbox(
|
| 600 |
+
label="Prompt",
|
| 601 |
+
value=default_prompt_i2v,
|
| 602 |
+
lines=3,
|
| 603 |
+
placeholder="Describe the desired animation or motion",
|
| 604 |
+
elem_classes=["gradio-component"]
|
| 605 |
+
)
|
| 606 |
+
generate_button = gr.Button(
|
| 607 |
+
"Generate Video",
|
| 608 |
+
variant="primary",
|
| 609 |
+
elem_classes=["gradio-component", "gr-button-primary"]
|
| 610 |
+
)
|
| 611 |
+
output_video = gr.Video(
|
| 612 |
+
label="Generated Video",
|
| 613 |
+
autoplay=True,
|
| 614 |
+
interactive=False,
|
| 615 |
+
show_download_button=True,
|
| 616 |
+
show_share_button=False,
|
| 617 |
+
elem_classes=["gradio-component", "image-container"]
|
| 618 |
+
)
|
| 619 |
|
| 620 |
+
generate_button.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 621 |
fn=generate_video,
|
| 622 |
inputs=[
|
| 623 |
+
input_image, prompt,
|
| 624 |
gr.State(value=4), gr.State(value=default_negative_prompt),
|
| 625 |
gr.State(value=5.0), gr.State(value=1), gr.State(value=1),
|
| 626 |
gr.State(value=42), gr.State(value=True)
|
| 627 |
],
|
| 628 |
+
outputs=[output_video, gr.State(value=42)]
|
| 629 |
)
|
| 630 |
|
| 631 |
return demo
|
| 632 |
|
| 633 |
if __name__ == "__main__":
|
| 634 |
demo = create_demo()
|
| 635 |
+
demo.queue().launch(share=True)
|