yejunliang23 commited on
Commit
f601d69
·
unverified ·
1 Parent(s): c4e7abe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -11
app.py CHANGED
@@ -52,7 +52,7 @@ def chat_qwen_vl(message: str, history: list, temperature: float = 0.1, max_new_
52
  )
53
  print(text)
54
  image_inputs, video_inputs = process_vision_info(messages)
55
- inputs = processor(
56
  text=[text],
57
  images=image_inputs,
58
  videos=video_inputs,
@@ -61,19 +61,34 @@ def chat_qwen_vl(message: str, history: list, temperature: float = 0.1, max_new_
61
  ).to(model.device)
62
 
63
  # 2. 把 streamer 和生成参数一起传给 model.generate
64
- gen_kwargs = dict(
65
- **inputs, # 包含 input_ids, pixel_values, attention_mask 等
66
- top_k=1024,
 
 
 
 
 
 
 
67
  max_new_tokens=max_new_tokens,
 
68
  temperature=temperature,
 
 
69
  top_p=0.1
70
- )
71
- generated_ids = model.generate(**gen_kwargs)
72
- generated_ids_trimmed = [
73
- out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]
74
- output_text = processor.batch_decode(
75
- generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
76
- yield output_text
 
 
 
 
 
77
 
78
 
79
  # --------- 3D Mesh Coloring Function ---------
 
52
  )
53
  print(text)
54
  image_inputs, video_inputs = process_vision_info(messages)
55
+ input_ids = processor(
56
  text=[text],
57
  images=image_inputs,
58
  videos=video_inputs,
 
61
  ).to(model.device)
62
 
63
  # 2. 把 streamer 和生成参数一起传给 model.generate
64
+ streamer = TextIteratorStreamer(
65
+ tokenizer,
66
+ timeout=100.0,
67
+ skip_prompt=True,
68
+ skip_special_tokens=True
69
+ )
70
+ #print(input_ids)
71
+ generate_kwargs = dict(
72
+ input_ids= input_ids["input_ids"],
73
+ streamer=streamer,
74
  max_new_tokens=max_new_tokens,
75
+ do_sample=True,
76
  temperature=temperature,
77
+ eos_token_id=terminators,
78
+ top_k=1024,
79
  top_p=0.1
80
+ )
81
+
82
+ # 4. 后台线程启动生成
83
+ Thread(target=model.generate, kwargs=generate_kwargs).start()
84
+
85
+ # 5. 主线程读取 streamer 并 yield
86
+ buffer = []
87
+ for chunk in streamer:
88
+ print(chunk)
89
+ buffer.append(chunk)
90
+ # 每次新到一个片段,就拼接并返回给前端
91
+ yield "".join(buffer)
92
 
93
 
94
  # --------- 3D Mesh Coloring Function ---------