hsuwill000 commited on
Commit
582e4de
·
verified ·
1 Parent(s): 5c0d84c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -3,10 +3,12 @@ import time
3
  import openvino_genai as ov_genai
4
  import numpy as np
5
  import gradio as gr
 
6
 
7
  # 下載模型
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
 
@@ -18,9 +20,15 @@ tokenizer.set_chat_template(tokenizer.chat_template)
18
 
19
 
20
  def generate_response(prompt):
21
- output = pipe.generate([prompt], max_length=1024)
22
- tokenpersec=f'Throughput: {output.perf_metrics.get_throughput().mean:.2f} tokens/s'
23
- return tokenpersec,output
 
 
 
 
 
 
24
 
25
  # 建立 Gradio 介面
26
  demo = gr.Interface(
 
3
  import openvino_genai as ov_genai
4
  import numpy as np
5
  import gradio as gr
6
+ import re
7
 
8
  # 下載模型
9
  model_id = "OpenVINO/Qwen3-0.6B-int4-ov"
10
  model_path = "Qwen3-0.6B-int4-ov"
11
+ match = re.search(r"<think>(.*?)</think>(.*)", text, re.DOTALL)
12
 
13
  hf_hub.snapshot_download(model_id, local_dir=model_path, local_dir_use_symlinks=False)
14
 
 
20
 
21
 
22
  def generate_response(prompt):
23
+ generated = pipe.generate([prompt], max_length=1024)
24
+ tokenpersec=f'{output.perf_metrics.get_throughput().mean:.2f}'
25
+ match = re.search(r"<think>(.*?)</think>(.*)", generated, re.DOTALL)
26
+
27
+ if match:
28
+ thinking = match.group(1).strip()
29
+ content = match.group(2).strip()
30
+ return tokenpersec, thinking, content
31
+
32
 
33
  # 建立 Gradio 介面
34
  demo = gr.Interface(