sayakpaul HF Staff commited on
Commit
7bf5ca7
·
1 Parent(s): 45c0c4e
__pycache__/optimization.cpython-310.pyc ADDED
Binary file (1.67 kB). View file
 
app.py CHANGED
@@ -21,42 +21,58 @@ def push_to_hub(repo_id, filename, oauth_token: gr.OAuthToken):
21
  raise NotImplementedError("The filename must end with a `.pt2` extension.")
22
 
23
  # this will throw if token is invalid
24
- _ = whoami(oauth_token.token)
25
-
26
- # --- Ahead-of-time compilation ---
27
- compiled_transformer = compile_transformer(pipe, prompt="prompt")
28
-
29
- token = oauth_token.token
30
- out = _push_compiled_graph_to_hub(
31
- compiled_transformer.archive_file,
32
- repo_id=repo_id,
33
- token=token,
34
- path_in_repo=filename
35
- )
36
- if not isinstance(out, str) and hasattr(out, "commit_url"):
37
- commit_url = out.commit_url
38
- return f"[{commit_url}]({commit_url})"
39
- else:
40
- return out
41
-
42
 
43
- css = """
44
- #app {max-width: 840px; margin: 0 auto;}
45
- """
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  with gr.Blocks(css=css) as demo:
48
- gr.Markdown("## Compile a model graph ahead of time & push to the Hub")
49
- gr.Markdown("Enter a **repo_id** and **filename**. This repo automatically compiles the [QwenImage](https://hf.co/Qwen/Qwen-Image) model on start.")
 
50
 
51
- with gr.Row():
52
  repo_id = gr.Textbox(label="repo_id", placeholder="e.g. sayakpaul/qwen-aot")
53
  filename = gr.Textbox(label="filename", placeholder="e.g. compiled.pt2")
54
 
55
- run = gr.Button("Push graph to Hub", variant="primary")
56
 
57
- markdown_out = gr.Markdown()
58
 
59
  run.click(push_to_hub, inputs=[repo_id, filename], outputs=[markdown_out])
60
 
61
- if __name__ == "__main__":
62
- demo.launch(show_error=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  raise NotImplementedError("The filename must end with a `.pt2` extension.")
22
 
23
  # this will throw if token is invalid
24
+ try:
25
+ _ = whoami(oauth_token.token)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ # --- Ahead-of-time compilation ---
28
+ compiled_transformer = compile_transformer(pipe, prompt="prompt")
 
29
 
30
+ token = oauth_token.token
31
+ out = _push_compiled_graph_to_hub(
32
+ compiled_transformer.archive_file,
33
+ repo_id=repo_id,
34
+ token=token,
35
+ path_in_repo=filename
36
+ )
37
+ if not isinstance(out, str) and hasattr(out, "commit_url"):
38
+ commit_url = out.commit_url
39
+ return f"[{commit_url}]({commit_url})"
40
+ else:
41
+ return out
42
+ except Exception as e:
43
+ raise gr.Error(f"""Oops, you forgot to login. Please use the loggin button on the top left to migrate your repo {e}""")
44
+
45
+ css="""
46
+ #col-container {
47
+ margin: 0 auto;
48
+ max-width: 520px;
49
+ }
50
+ """
51
  with gr.Blocks(css=css) as demo:
52
+ with gr.Column(elem_id="col-container"):
53
+ gr.Markdown("## Compile QwenImage graph ahead of time & push to the Hub")
54
+ gr.Markdown("Enter a **repo_id** and **filename**. This repo automatically compiles the [QwenImage](https://hf.co/Qwen/Qwen-Image) model on start.")
55
 
 
56
  repo_id = gr.Textbox(label="repo_id", placeholder="e.g. sayakpaul/qwen-aot")
57
  filename = gr.Textbox(label="filename", placeholder="e.g. compiled.pt2")
58
 
59
+ run = gr.Button("Push graph to Hub", variant="primary")
60
 
61
+ markdown_out = gr.Markdown()
62
 
63
  run.click(push_to_hub, inputs=[repo_id, filename], outputs=[markdown_out])
64
 
65
+ def swap_visibilty(profile: gr.OAuthProfile | None):
66
+ return gr.update(elem_classes=["main_ui_logged_in"]) if profile else gr.update(elem_classes=["main_ui_logged_out"])
67
+
68
+ css_login = '''
69
+ .main_ui_logged_out{opacity: 0.3; pointer-events: none; margin: 0 auto; max-width: 520px}
70
+ '''
71
+ with gr.Blocks(css=css_login) as demo_login:
72
+ gr.LoginButton()
73
+ with gr.Column(elem_classes="main_ui_logged_out") as main_ui:
74
+ demo.render()
75
+ demo_login.load(fn=swap_visibilty, outputs=main_ui)
76
+
77
+ demo_login.queue()
78
+ demo_login.launch()
qwenimage/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (167 Bytes). View file
 
qwenimage/__pycache__/qwen_fa3_processor.cpython-310.pyc ADDED
Binary file (4.1 kB). View file
 
requirements.txt CHANGED
@@ -3,4 +3,5 @@ transformers
3
  accelerate
4
  safetensors
5
  sentencepiece
6
- kernels
 
 
3
  accelerate
4
  safetensors
5
  sentencepiece
6
+ kernels
7
+ gradio[oauth]