Spaces:
Running
Running
MekkCyber
commited on
Commit
·
1b761b3
1
Parent(s):
2d99709
update
Browse files
app.py
CHANGED
@@ -89,61 +89,83 @@ def run_transformers(model_name, input_text, num_tokens):
|
|
89 |
|
90 |
# Gradio Interface
|
91 |
def interface():
|
92 |
-
with gr.Blocks(css="
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
gr.Markdown(
|
97 |
"""
|
98 |
-
<h1 style="text-align: center; color: #4A148C;">BitNet.cpp Speed Demonstration
|
99 |
-
<p style="text-align: center; color: #6A1B9A;">Compare the speed and performance of BitNet with
|
100 |
-
""",
|
101 |
elem_id="header"
|
102 |
)
|
103 |
|
104 |
-
# Model
|
105 |
-
with gr.
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
# Actions
|
138 |
setup_button.click(setup_bitnet, inputs=model_dropdown, outputs=setup_status)
|
139 |
infer_button.click(run_inference, inputs=[model_dropdown, input_text, num_tokens], outputs=[result_output, time_output])
|
140 |
compare_button.click(run_transformers, inputs=[transformer_model_dropdown, input_text_tr, num_tokens], outputs=[transformer_result_output, transformer_time_output])
|
141 |
|
142 |
-
# Launch the Gradio app
|
143 |
return demo
|
144 |
|
145 |
demo = interface()
|
146 |
-
|
147 |
# # Access FastAPI app instance from Gradio
|
148 |
# fastapi_app = demo.app
|
149 |
|
|
|
89 |
|
90 |
# Gradio Interface
|
91 |
def interface():
|
92 |
+
with gr.Blocks(css="""
|
93 |
+
.gr-button {background-color: #5C6BC0; color: white; border-radius: 8px; padding: 8px 12px;}
|
94 |
+
.gr-button:hover {background-color: #3F51B5;}
|
95 |
+
#header {font-family: 'Arial', sans-serif;}
|
96 |
+
.container {background-color: #F3E5F5; border-radius: 10px; padding: 20px; margin: 10px 0;}
|
97 |
+
.container h2 {color: #6A1B9A; text-align: center;}
|
98 |
+
.center {text-align: center;}
|
99 |
+
.center-button {display: flex; justify-content: center; margin: 10px;}
|
100 |
+
""") as demo:
|
101 |
+
|
102 |
+
# Header
|
103 |
gr.Markdown(
|
104 |
"""
|
105 |
+
<h1 style="text-align: center; color: #4A148C;">BitNet.cpp Speed Demonstration 💻</h1>
|
106 |
+
<p style="text-align: center; color: #6A1B9A;">Compare the speed and performance of BitNet with popular Transformer models.</p>
|
107 |
+
""",
|
108 |
elem_id="header"
|
109 |
)
|
110 |
|
111 |
+
# Model Selection and Setup
|
112 |
+
with gr.Box(elem_id="container"):
|
113 |
+
with gr.Row():
|
114 |
+
model_dropdown = gr.Dropdown(
|
115 |
+
label="Select Model",
|
116 |
+
choices=[
|
117 |
+
"HF1BitLLM/Llama3-8B-1.58-100B-tokens",
|
118 |
+
"1bitLLM/bitnet_b1_58-3B",
|
119 |
+
"1bitLLM/bitnet_b1_58-large"
|
120 |
+
],
|
121 |
+
value="HF1BitLLM/Llama3-8B-1.58-100B-tokens",
|
122 |
+
interactive=True
|
123 |
+
)
|
124 |
+
setup_button = gr.Button("Run Setup")
|
125 |
+
setup_status = gr.Textbox(label="Setup Status", interactive=False, placeholder="Setup status will appear here...")
|
126 |
+
|
127 |
+
# Inference Section
|
128 |
+
with gr.Box(elem_id="container"):
|
129 |
+
gr.Markdown("<h2>BitNet Inference</h2>")
|
130 |
+
with gr.Row():
|
131 |
+
num_tokens = gr.Slider(
|
132 |
+
minimum=1, maximum=100,
|
133 |
+
label="Number of Tokens to Generate",
|
134 |
+
value=50, step=1
|
135 |
+
)
|
136 |
+
input_text = gr.Textbox(
|
137 |
+
label="Input Text",
|
138 |
+
placeholder="Enter your input text here..."
|
139 |
+
)
|
140 |
+
with gr.Row():
|
141 |
+
infer_button = gr.Button("Run Inference")
|
142 |
+
result_output = gr.Textbox(label="Output", interactive=False, placeholder="Inference output will appear here...")
|
143 |
+
time_output = gr.Textbox(label="Inference Time", interactive=False, placeholder="Inference time will appear here...")
|
144 |
+
|
145 |
+
# Comparison with Transformers Section
|
146 |
+
with gr.Box(elem_id="container"):
|
147 |
+
gr.Markdown("<h2>Compare with Transformers</h2>")
|
148 |
+
with gr.Row():
|
149 |
+
transformer_model_dropdown = gr.Dropdown(
|
150 |
+
label="Select Transformers Model",
|
151 |
+
choices=["TinyLlama/TinyLlama_v1.1", "HuggingFaceTB/SmolLM-360M"],
|
152 |
+
value="TinyLlama/TinyLlama_v1.1",
|
153 |
+
interactive=True
|
154 |
+
)
|
155 |
+
input_text_tr = gr.Textbox(label="Input Text", placeholder="Enter your input text here...")
|
156 |
+
with gr.Row():
|
157 |
+
compare_button = gr.Button("Run Transformers Inference")
|
158 |
+
transformer_result_output = gr.Textbox(label="Transformers Output", interactive=False, placeholder="Transformers output will appear here...")
|
159 |
+
transformer_time_output = gr.Textbox(label="Transformers Inference Time", interactive=False, placeholder="Transformers inference time will appear here...")
|
160 |
|
161 |
# Actions
|
162 |
setup_button.click(setup_bitnet, inputs=model_dropdown, outputs=setup_status)
|
163 |
infer_button.click(run_inference, inputs=[model_dropdown, input_text, num_tokens], outputs=[result_output, time_output])
|
164 |
compare_button.click(run_transformers, inputs=[transformer_model_dropdown, input_text_tr, num_tokens], outputs=[transformer_result_output, transformer_time_output])
|
165 |
|
|
|
166 |
return demo
|
167 |
|
168 |
demo = interface()
|
|
|
169 |
# # Access FastAPI app instance from Gradio
|
170 |
# fastapi_app = demo.app
|
171 |
|