Spaces:
Sleeping
Sleeping
| 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("Click Sign in with Hugging Face button to use this app for free") | |
| # 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 Sign in with Hugging Face using the button 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, | |
| ) |