akhaliq HF Staff commited on
Commit
8936ae6
·
verified ·
1 Parent(s): 71a9ef0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -2,15 +2,29 @@ import gradio as gr
2
  from models import generate_image, MODEL_ID
3
  from config import APPLE_TENCENT_THEME
4
 
 
 
 
 
 
 
 
 
 
 
5
  def create_ui():
6
  with gr.Blocks(title=f"Tencent HunyuanImage-3.0 Demo", theme=APPLE_TENCENT_THEME) as demo:
7
  gr.HTML(
8
  f"<div style='text-align: center; max-width: 700px; margin: 0 auto;'>"
9
  f"<h1>Tencent {MODEL_ID.split('/')[-1]}</h1>"
10
  f"<p>Generate images using Tencent's state-of-the-art model hosted by FAL AI.</p>"
 
11
  f"Built with <a href='https://huggingface.co/spaces/akhaliq/anycoder' target='_blank'>anycoder</a>"
12
  f"</div>"
13
  )
 
 
 
14
 
15
  with gr.Row():
16
  with gr.Column(scale=1):
@@ -30,14 +44,14 @@ def create_ui():
30
  show_download_button=True
31
  )
32
 
33
- # Set up the event listener with all queue-related features disabled
34
  generate_btn.click(
35
- fn=generate_image,
36
  inputs=[prompt_input],
37
  outputs=[output_image],
38
- queue=False, # Disable queue for this event
39
- api_name=False, # Disable API endpoint creation
40
- show_api=False, # Don't show this in API docs
41
  )
42
 
43
  # Example usage guidance with queue features disabled
@@ -47,19 +61,20 @@ def create_ui():
47
  ],
48
  inputs=prompt_input,
49
  outputs=output_image,
50
- fn=generate_image,
51
- cache_examples=False, # Don't cache examples
52
- api_name=False, # No API endpoint for examples
53
- show_api=False, # Don't show in API docs
54
  )
55
 
56
  return demo
57
 
58
  if __name__ == "__main__":
59
  app = create_ui()
60
- # Launch without queue, API, and monitoring features
 
61
  app.launch(
62
- show_api=False, # Hide API documentation
63
- enable_monitoring=False, # Disable monitoring to prevent any background queuing
64
- quiet=True, # Reduce console output
65
  )
 
2
  from models import generate_image, MODEL_ID
3
  from config import APPLE_TENCENT_THEME
4
 
5
+ def generate_image_with_auth(prompt: str, profile: gr.OAuthProfile | None):
6
+ """
7
+ Wrapper function that checks if user is logged in before generating image.
8
+ """
9
+ if profile is None:
10
+ raise gr.Error("Please log in with Hugging Face to use this app.")
11
+
12
+ # User is logged in, proceed with image generation
13
+ return generate_image(prompt)
14
+
15
  def create_ui():
16
  with gr.Blocks(title=f"Tencent HunyuanImage-3.0 Demo", theme=APPLE_TENCENT_THEME) as demo:
17
  gr.HTML(
18
  f"<div style='text-align: center; max-width: 700px; margin: 0 auto;'>"
19
  f"<h1>Tencent {MODEL_ID.split('/')[-1]}</h1>"
20
  f"<p>Generate images using Tencent's state-of-the-art model hosted by FAL AI.</p>"
21
+ f"<p style='color: orange;'>⚠️ You must log in with Hugging Face to use this app.</p>"
22
  f"Built with <a href='https://huggingface.co/spaces/akhaliq/anycoder' target='_blank'>anycoder</a>"
23
  f"</div>"
24
  )
25
+
26
+ # Add login button - required for OAuth
27
+ gr.LoginButton()
28
 
29
  with gr.Row():
30
  with gr.Column(scale=1):
 
44
  show_download_button=True
45
  )
46
 
47
+ # Set up the event listener - note the function now takes OAuthProfile
48
  generate_btn.click(
49
+ fn=generate_image_with_auth,
50
  inputs=[prompt_input],
51
  outputs=[output_image],
52
+ queue=False,
53
+ api_name=False,
54
+ show_api=False,
55
  )
56
 
57
  # Example usage guidance with queue features disabled
 
61
  ],
62
  inputs=prompt_input,
63
  outputs=output_image,
64
+ fn=generate_image, # Examples use the original function
65
+ cache_examples=False,
66
+ api_name=False,
67
+ show_api=False,
68
  )
69
 
70
  return demo
71
 
72
  if __name__ == "__main__":
73
  app = create_ui()
74
+ # Launch without special auth parameters
75
+ # OAuth is enabled via Space metadata (hf_oauth: true in README.md)
76
  app.launch(
77
+ show_api=False,
78
+ enable_monitoring=False,
79
+ quiet=True,
80
  )