Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -18,62 +18,19 @@ tokenizer.set_chat_template(tokenizer.chat_template)
|
|
18 |
|
19 |
|
20 |
def generate_response(prompt):
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
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'
|
38 |
-
|
39 |
-
return generated_text, performance_metrics
|
40 |
-
|
41 |
-
|
42 |
-
def main():
|
43 |
-
"""
|
44 |
-
Creates and launches the Gradio interface.
|
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 |
-
|
75 |
-
demo.launch()
|
76 |
-
|
77 |
|
78 |
if __name__ == "__main__":
|
79 |
-
|
|
|
18 |
|
19 |
|
20 |
def generate_response(prompt):
|
21 |
+
generated = pipe.generate([prompt], max_length=1024)
|
22 |
+
return generated
|
23 |
+
|
24 |
+
# 建立 Gradio 介面
|
25 |
+
demo = gr.Interface(
|
26 |
+
fn=generate_response,
|
27 |
+
inputs=gr.Textbox(lines=5, label="輸入提示 (Prompt)"),
|
28 |
+
outputs=[
|
29 |
+
gr.Textbox(label="回應")
|
30 |
+
],
|
31 |
+
title="Qwen3-0.6B OpenVINO + Gradio",
|
32 |
+
description="基於 OpenVINO 最佳化的 Qwen3-0.6B 推理應用,支援思考過程分離與 GUI。"
|
33 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
if __name__ == "__main__":
|
36 |
+
demo.launch()
|