File size: 2,930 Bytes
3f6c6eb
 
f05400f
3f6c6eb
8936ae6
 
 
 
 
 
 
 
 
 
3f6c6eb
f05400f
71a9ef0
 
 
 
8936ae6
71a9ef0
 
 
8936ae6
 
 
71a9ef0
3f6c6eb
 
71a9ef0
 
 
 
93d08c5
71a9ef0
93d08c5
71a9ef0
 
 
 
 
 
 
93d08c5
71a9ef0
8936ae6
3f6c6eb
8936ae6
71a9ef0
 
8936ae6
 
 
3f6c6eb
 
71a9ef0
 
 
 
 
 
 
8936ae6
 
 
 
3f6c6eb
 
 
 
 
 
8936ae6
 
f561a3b
8936ae6
 
 
71a9ef0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import gradio as gr
from models import generate_image, MODEL_ID
from config import APPLE_TENCENT_THEME

def generate_image_with_auth(prompt: str, profile: gr.OAuthProfile | None):
    """
    Wrapper function that checks if user is logged in before generating image.
    """
    if profile is None:
        raise gr.Error("Please log in with Hugging Face to use this app.")
    
    # User is logged in, proceed with image generation
    return generate_image(prompt)

def create_ui():
    with gr.Blocks(title=f"Tencent HunyuanImage-3.0 Demo", theme=APPLE_TENCENT_THEME) as demo:
        gr.HTML(
            f"<div style='text-align: center; max-width: 700px; margin: 0 auto;'>"
            f"<h1>Tencent {MODEL_ID.split('/')[-1]}</h1>"
            f"<p>Generate images using Tencent's state-of-the-art model hosted by FAL AI.</p>"
            f"<p style='color: orange;'>⚠️ You must log in with Hugging Face to use this app.</p>"
            f"Built with <a href='https://huggingface.co/spaces/akhaliq/anycoder' target='_blank'>anycoder</a>"
            f"</div>"
        )
        
        # Add login button - required for OAuth
        gr.LoginButton()

        with gr.Row():
            with gr.Column(scale=1):
                prompt_input = gr.Textbox(
                    label="Prompt",
                    placeholder="e.g., A detailed watercolor painting of a small red fox sleeping on a pile of autumn leaves.",
                    lines=4
                )
                generate_btn = gr.Button("🎨 Generate Image", variant="primary")
                
            with gr.Column(scale=1):
                output_image = gr.Image(
                    label="Generated Image",
                    height=512,
                    width=512,
                    interactive=False,
                    show_download_button=True
                )

        # Set up the event listener - note the function now takes OAuthProfile
        generate_btn.click(
            fn=generate_image_with_auth,
            inputs=[prompt_input],
            outputs=[output_image],
            queue=False,
            api_name=False,
            show_api=False,
        )
        
        # Example usage guidance with queue features disabled
        gr.Examples(
            examples=[
                "A detailed watercolor painting of a small red fox sleeping on a pile of autumn leaves."
            ],
            inputs=prompt_input,
            outputs=output_image,
            fn=generate_image,  # Examples use the original function
            cache_examples=False,
            api_name=False,
            show_api=False,
        )

    return demo

if __name__ == "__main__":
    app = create_ui()
    # Launch without special auth parameters
    # OAuth is enabled via Space metadata (hf_oauth: true in README.md)
    app.launch(
        show_api=False,
        enable_monitoring=False,
        quiet=True,
    )