Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,8 @@ def start_chat():
|
|
20 |
def finish_chat():
|
21 |
pipe.finish_chat()
|
22 |
return "🛑 結束對話!"
|
|
|
|
|
23 |
|
24 |
# 建立推論函式:使用 streamer 並回傳 generator 結果
|
25 |
def generate_stream(prompt):
|
@@ -32,7 +34,13 @@ def generate_stream(prompt):
|
|
32 |
|
33 |
def worker():
|
34 |
# 在背景 thread 中做推論
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
q.put(None) # 結束符號
|
37 |
|
38 |
threading.Thread(target=worker).start()
|
@@ -55,11 +63,13 @@ with gr.Blocks(css="""
|
|
55 |
}
|
56 |
""") as demo:
|
57 |
gr.Markdown("## 🧠 OpenVINO Streaming Demo with Gradio Textbox")
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
63 |
start_btn.click(fn=start_chat, outputs=status_box)
|
64 |
end_btn.click(fn=finish_chat, outputs=status_box)
|
65 |
|
@@ -72,4 +82,4 @@ with gr.Blocks(css="""
|
|
72 |
# 當按鈕被按下時,呼叫 generate_stream 並更新 textbox_output
|
73 |
button.click(fn=generate_stream, inputs=textbox_input, outputs=textbox_output)
|
74 |
|
75 |
-
demo.launch()
|
|
|
20 |
def finish_chat():
|
21 |
pipe.finish_chat()
|
22 |
return "🛑 結束對話!"
|
23 |
+
|
24 |
+
|
25 |
|
26 |
# 建立推論函式:使用 streamer 並回傳 generator 結果
|
27 |
def generate_stream(prompt):
|
|
|
34 |
|
35 |
def worker():
|
36 |
# 在背景 thread 中做推論
|
37 |
+
try
|
38 |
+
gen_result = pipe.generate([prompt], streamer=streamer, max_new_tokens=4096)
|
39 |
+
tps = gen_result.perf_metrics.get_throughput().mean
|
40 |
+
result_container["tps"] = f"{tps:.2f} tokens/s"
|
41 |
+
except Exception as e:
|
42 |
+
result_container["tps"] = f"❌ {str(e)}"
|
43 |
+
|
44 |
q.put(None) # 結束符號
|
45 |
|
46 |
threading.Thread(target=worker).start()
|
|
|
63 |
}
|
64 |
""") as demo:
|
65 |
gr.Markdown("## 🧠 OpenVINO Streaming Demo with Gradio Textbox")
|
66 |
+
|
67 |
+
with gr.Row():
|
68 |
+
start_btn = gr.Button("開始對話")
|
69 |
+
end_btn = gr.Button("結束對話")
|
70 |
+
status_box = gr.Textbox(label="狀態", interactive=False)
|
71 |
+
TPS_box = gr.Textbox(label="TPS", interactive=False)
|
72 |
+
|
73 |
start_btn.click(fn=start_chat, outputs=status_box)
|
74 |
end_btn.click(fn=finish_chat, outputs=status_box)
|
75 |
|
|
|
82 |
# 當按鈕被按下時,呼叫 generate_stream 並更新 textbox_output
|
83 |
button.click(fn=generate_stream, inputs=textbox_input, outputs=textbox_output)
|
84 |
|
85 |
+
demo.launch()
|