Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import gradio as gr
|
|
8 |
model_id = "OpenVINO/Qwen3-0.6B-int4-ov"
|
9 |
model_path = "Qwen3-0.6B-int4-ov"
|
10 |
|
11 |
-
hf_hub.snapshot_download(model_id, local_dir=model_path, local_dir_use_symlinks=False)
|
12 |
|
13 |
# 建立推理管線
|
14 |
device = "CPU"
|
@@ -31,7 +31,7 @@ def generate_response(prompt):
|
|
31 |
output = pipe.generate([prompt], max_length=1024)
|
32 |
end_time = time.time()
|
33 |
|
34 |
-
generated_text = output.text[0]
|
35 |
|
36 |
performance_metrics = f"Generate duration: {output.perf_metrics.get_generate_duration().mean:.2f}ms\n"
|
37 |
performance_metrics += f'Throughput: {output.perf_metrics.get_throughput().mean:.2f} tokens/s'
|
@@ -45,27 +45,30 @@ def main():
|
|
45 |
"""
|
46 |
|
47 |
with gr.Blocks() as demo:
|
48 |
-
gr.Markdown("# OpenVINO Qwen3-8B Demo")
|
49 |
prompt_input = gr.Textbox(lines=3, label="Enter your prompt:")
|
50 |
output_text = gr.Textbox(label="Generated Response")
|
51 |
-
performance_text = gr.Textbox(label="Performance Metrics", visible=False)
|
|
|
52 |
|
53 |
def update_output(prompt):
|
54 |
response, performance = generate_response(prompt)
|
55 |
-
return response, performance
|
56 |
|
57 |
prompt_input.change(
|
58 |
fn=update_output,
|
59 |
inputs=prompt_input,
|
60 |
-
outputs=[output_text, performance_text],
|
61 |
)
|
62 |
|
63 |
# Button to show/hide performance metrics
|
64 |
show_metrics_button = gr.Button("Show/Hide Performance Metrics")
|
|
|
|
|
65 |
show_metrics_button.click(
|
66 |
-
fn=
|
67 |
-
inputs=[
|
68 |
-
outputs=[performance_text.visible],
|
69 |
)
|
70 |
|
71 |
|
|
|
8 |
model_id = "OpenVINO/Qwen3-0.6B-int4-ov"
|
9 |
model_path = "Qwen3-0.6B-int4-ov"
|
10 |
|
11 |
+
hf_hub.snapshot_download(model_id, local_dir=model_path, local_dir_use_symlinks=False)
|
12 |
|
13 |
# 建立推理管線
|
14 |
device = "CPU"
|
|
|
31 |
output = pipe.generate([prompt], max_length=1024)
|
32 |
end_time = time.time()
|
33 |
|
34 |
+
generated_text = output.text[0]
|
35 |
|
36 |
performance_metrics = f"Generate duration: {output.perf_metrics.get_generate_duration().mean:.2f}ms\n"
|
37 |
performance_metrics += f'Throughput: {output.perf_metrics.get_throughput().mean:.2f} tokens/s'
|
|
|
45 |
"""
|
46 |
|
47 |
with gr.Blocks() as demo:
|
48 |
+
gr.Markdown("# OpenVINO Qwen3-8B Demo")
|
49 |
prompt_input = gr.Textbox(lines=3, label="Enter your prompt:")
|
50 |
output_text = gr.Textbox(label="Generated Response")
|
51 |
+
performance_text = gr.Textbox(label="Performance Metrics", visible=False)
|
52 |
+
visibility_state = gr.State(False) # Store visibility state
|
53 |
|
54 |
def update_output(prompt):
|
55 |
response, performance = generate_response(prompt)
|
56 |
+
return response, performance
|
57 |
|
58 |
prompt_input.change(
|
59 |
fn=update_output,
|
60 |
inputs=prompt_input,
|
61 |
+
outputs=[output_text, performance_text],
|
62 |
)
|
63 |
|
64 |
# Button to show/hide performance metrics
|
65 |
show_metrics_button = gr.Button("Show/Hide Performance Metrics")
|
66 |
+
def toggle_visibility(visible):
|
67 |
+
return not visible, not visible
|
68 |
show_metrics_button.click(
|
69 |
+
fn=toggle_visibility,
|
70 |
+
inputs=[visibility_state],
|
71 |
+
outputs=[performance_text.visible, visibility_state],
|
72 |
)
|
73 |
|
74 |
|