Aditya Sahu commited on
Commit
e8828b9
·
verified ·
1 Parent(s): 14cb284

Add UI and Result Info

Browse files
Files changed (1) hide show
  1. app.py +108 -47
app.py CHANGED
@@ -3,29 +3,7 @@ import gradio as gr
3
  import tempfile
4
  import os
5
  import sr100_model_compiler
6
- #from huggingface_hub import HfApi
7
- #from huggingface_hub import whoami
8
- # Get top-level authorizations
9
- #oauth_info = {'username' : None, 'token' : None}
10
- #api = HfApi()
11
- #
12
- #def get_oauth_info(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
13
- # global oauth_info
14
- # global api
15
-
16
- # print(f'profile = {profile}')
17
- # if profile is None:
18
- # oauth_info['username'] = None
19
- # oauth_info['token'] = None
20
- # return "Please login to the Huggingface with login button"
21
- # else:
22
- # #print(f'Testing {profile} for username')
23
- # oauth_info['username'] = profile.username
24
- # oauth_info['token'] = oauth_token.token
25
- # org_names = [org["name"] for org in whoami(oauth_token.token)["orgs"]]
26
- #
27
- # return print(f'{profile.username}: {org_names}')
28
-
29
 
30
  def compile_model(model_name, vmem_value, lpmem_value):
31
 
@@ -47,32 +25,40 @@ def compile_model(model_name, vmem_value, lpmem_value):
47
  )
48
  print(results)
49
 
50
- output_text = ''
51
-
 
52
  if results['cycles_npu'] == 0:
53
- output_text = 'FAILURE cannot optimize TFLITE model for SR100'
54
- output_text += '<br><br>Compiler log<br>---------------------------------------'
55
- output_text += f'<br>{results["vela_log"]}'
 
 
 
 
 
 
56
  else:
57
  if success:
58
- output_text = 'SUCCESS, model fits on SR100'
 
 
 
59
  else:
60
- output_text = 'FAILURE, model does not fit on SR100'
 
 
 
61
 
 
 
 
 
62
  weights_size = results['weights_size'] / 1000.0
63
  arena_size = results['arena_cache_size'] / 1000.0
64
- clock = results['core_clock'] / 1.0e6
65
  infer_time = results['inference_time'] * 1000.0
66
  infer_fps = results['inferences_per_sec']
67
-
68
- output_text += f'<br>clock = {clock:0.1f} MHz'
69
-
70
- output_text += f'<br>inference time = {infer_time:0.1f}ms - {infer_fps:0.1f} fps'
71
- output_text += f'<br>Arena cache size = {arena_size:0.3f} kB'
72
- output_text += f'<br>Model size = {weights_size:0.3f} kB'
73
- output_text += f'<br>model loc = {results["model_loc"]}'
74
- output_text += f'<br>System config = {results["system_config"]}'
75
-
76
  vmem_size = results['vmem_size'] / 1000.0
77
  lpmem_size = results['lpmem_size'] / 1000.0
78
  vmem_size_limit = results['vmem_size_limit'] / 1000.0
@@ -80,18 +66,83 @@ def compile_model(model_name, vmem_value, lpmem_value):
80
  vmem_perc = results['vmem_size'] * 100.0 / results['vmem_size_limit']
81
  lpmem_perc = results['lpmem_size'] * 100.0 / results['lpmem_size_limit']
82
 
83
- output_text += f'<br>vmem_size = {vmem_size:0.3f} kB ({vmem_perc:0.1f}% of {vmem_size_limit:0.3f} kB limit)'
84
- output_text += f'<br>lpmem_size = {lpmem_size:0.3f} kB ({lpmem_perc:0.1f}% of {lpmem_size_limit:0.3f} kB limit)'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
-
87
- return output_text
88
 
89
  # Get all available models
90
  model_choices = glob.glob('models/*.tflite')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
- with gr.Blocks() as demo:
93
  #gr.LoginButton()
94
- text1 = gr.Markdown("SR100 Model Optimizer Demo - Compile a tflite model to SR100 and see if it fits")
 
95
  #user_text = gr.Markdown("")
96
 
97
  # Setup model inputs
@@ -108,11 +159,21 @@ with gr.Blocks() as demo:
108
 
109
  # Run the compile
110
  compile_btn = gr.Button("Compile Model")
111
- compile_text = gr.Markdown("Waiting for model results")
112
 
113
  # Compute options
114
  compile_btn.click(compile_model, inputs=[model_dropdown, vmem_slider, lpmem_slider], outputs=[compile_text])
115
  #demo.load(get_oauth_info, inputs=None, outputs=user_text)
 
 
 
 
 
 
 
 
 
 
116
 
117
  if __name__ == "__main__":
118
  demo.launch()
 
3
  import tempfile
4
  import os
5
  import sr100_model_compiler
6
+ import html
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  def compile_model(model_name, vmem_value, lpmem_value):
9
 
 
25
  )
26
  print(results)
27
 
28
+ # Format results in nicely styled HTML like in old.py
29
+ output = []
30
+
31
  if results['cycles_npu'] == 0:
32
+ output.append(
33
+ "<div style='color:#d32f2f; font-weight:bold; font-size:1.2em;'>"
34
+ "❌ FAILURE: This model does not utilize NPU, Please see if model has supported ops, thus cannot optimize for SR100</div>"
35
+ )
36
+ output.append("<div style='margin-top:0.5em;color:#000;'>Compiler log:</div>")
37
+ output.append(
38
+ f"<pre style='white-space:pre-wrap; background:#f6f8fa; padding:8px; border-radius:6px; color:#000;'>"
39
+ f"{html.escape(results.get('vela_log', 'No log available'))}</pre>"
40
+ )
41
  else:
42
  if success:
43
+ output.append(
44
+ "<div style='color:#007dc3; font-weight:bold; font-size:1.2em;'>"
45
+ "✅ SUCCESS: Model fits on SR100 and below is the estimates Performance</div>"
46
+ )
47
  else:
48
+ output.append(
49
+ "<div style='color:#d32f2f; font-weight:bold; font-size:1.2em;'>"
50
+ "❌ FAILURE: Model does not fit on SR100, Please check Memory usage of Model</div>"
51
+ )
52
 
53
+ # Format metrics in a nice table
54
+ table_rows = []
55
+
56
+ # Calculate all the metrics
57
  weights_size = results['weights_size'] / 1000.0
58
  arena_size = results['arena_cache_size'] / 1000.0
59
+ clock = results['core_clock'] / 1.0e6
60
  infer_time = results['inference_time'] * 1000.0
61
  infer_fps = results['inferences_per_sec']
 
 
 
 
 
 
 
 
 
62
  vmem_size = results['vmem_size'] / 1000.0
63
  lpmem_size = results['lpmem_size'] / 1000.0
64
  vmem_size_limit = results['vmem_size_limit'] / 1000.0
 
66
  vmem_perc = results['vmem_size'] * 100.0 / results['vmem_size_limit']
67
  lpmem_perc = results['lpmem_size'] * 100.0 / results['lpmem_size_limit']
68
 
69
+ # Add rows to the table
70
+ metrics = [
71
+ ("Clock Frequency", f"{clock:0.1f} MHz"),
72
+ ("Inference Time", f"{infer_time:0.1f} ms"),
73
+ ("Inferences Per Second", f"{infer_fps:0.1f} fps"),
74
+ ("Arena Cache Size", f"{arena_size:0.3f} kB"),
75
+ ("Model Size", f"{weights_size:0.3f} kB"),
76
+ ("Model Location", f"{results['model_loc']}"),
77
+ ("System Configuration", f"{results['system_config']}"),
78
+ ("VMEM Size", f"{vmem_size:0.3f} kB ({vmem_perc:0.1f}% of {vmem_size_limit:0.3f} kB limit)"),
79
+ ("LPMEM Size", f"{lpmem_size:0.3f} kB ({lpmem_perc:0.1f}% of {lpmem_size_limit:0.3f} kB limit)")
80
+ ]
81
+
82
+ for label, value in metrics:
83
+ table_rows.append(
84
+ "<tr>"
85
+ f"<td style='padding:4px 12px; font-weight:bold; border-bottom:1px solid #eee; color:#000;'>{label}</td>"
86
+ f"<td style='padding:4px 12px; border-bottom:1px solid #eee; color:#000;'>{value}</td>"
87
+ "</tr>"
88
+ )
89
+
90
+ output.append(
91
+ "<table style='margin-top:1em; border-collapse:collapse; color:#000;'>"
92
+ + "".join(table_rows) + "</table>"
93
+ )
94
 
95
+ return "".join(output)
 
96
 
97
  # Get all available models
98
  model_choices = glob.glob('models/*.tflite')
99
+
100
+ # Custom CSS from old.py
101
+ custom_css = """
102
+ :root {
103
+ --color-accent: #007dc3;
104
+ --color-primary-500: #007dc3;
105
+ --color-primary-600: #007dc3;
106
+ }
107
+ body, .gradio-container, #root {
108
+ background: #fff !important;
109
+ }
110
+ /* Hide Gradio footer and settings */
111
+ footer, .gradio-footer, .svelte-1ipelgc, .gradio-logo, .gradio-app__settings {
112
+ display: none !important;
113
+ }
114
+ /* Style input labels and controls */
115
+ .gradio-slider label,
116
+ .gradio-radio label,
117
+ .gradio-dropdown label,
118
+ .gradio-file label {
119
+ color: #007dc3 !important;
120
+ font-weight: bold;
121
+ }
122
+ .gradio-slider input[type="range"]::-webkit-slider-thumb,
123
+ .gradio-slider input[type="range"]::-moz-range-thumb,
124
+ .gradio-slider input[type="range"]::-ms-thumb {
125
+ background: #007dc3 !important;
126
+ }
127
+ .gradio-radio input[type="radio"]:checked + span {
128
+ background: #007dc3 !important;
129
+ border-color: #007dc3 !important;
130
+ }
131
+ .gradio-dropdown select,
132
+ .gradio-file input[type="file"] {
133
+ border-color: #007dc3 !important;
134
+ }
135
+ .gradio-button {
136
+ background: #007dc3 !important;
137
+ color: #fff !important;
138
+ border: none !important;
139
+ }
140
+ """
141
 
142
+ with gr.Blocks(css=custom_css) as demo:
143
  #gr.LoginButton()
144
+ gr.Markdown("<h1 style='font-size:2.5em; color:#007dc3; margin-bottom:0;'>SR100 Model Compiler</h1>", elem_id="main_title")
145
+ gr.Markdown("<h3 style='margin-top:0; color:#000;'>Bring a TFlite INT8 model and compile it for Synaptics Astra SR100. Learn more at <a href='https://developer.synaptics.com/docs/sr/sr100/quick-start?utm_source=hf' target='_blank' style='color:#007dc3; text-decoration:underline;'>Synaptics AI Developer Zone</a></h3>", elem_id="subtitle")
146
  #user_text = gr.Markdown("")
147
 
148
  # Setup model inputs
 
159
 
160
  # Run the compile
161
  compile_btn = gr.Button("Compile Model")
162
+ compile_text = gr.Markdown("<span style='color:#000;'>Waiting for model results</span>")
163
 
164
  # Compute options
165
  compile_btn.click(compile_model, inputs=[model_dropdown, vmem_slider, lpmem_slider], outputs=[compile_text])
166
  #demo.load(get_oauth_info, inputs=None, outputs=user_text)
167
+
168
+ # Add footer content from old.py
169
+ gr.HTML("""
170
+ <div style="max-width: 800px; margin: 2rem auto; background: white; color: black; border-radius: 12px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); border: 1px solid #e5e7eb; padding: 1.5rem; text-align: center;">
171
+ For a detailed walkthrough, please see our
172
+ <a href="http://localhost:3000/sr/evaluate-sr" target="_blank" style="color: #1a0dab;">Evaluate Model Guide</a>.<br>
173
+ To get started quickly, visit our
174
+ <a href="http://localhost:3000/sr/quick-start" target="_blank" style="color: #1a0dab;">SR Quick Start page</a>.
175
+ </div>
176
+ """)
177
 
178
  if __name__ == "__main__":
179
  demo.launch()