vc3vc3 commited on
Commit
faaec3e
·
verified ·
1 Parent(s): 2771b98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -20
app.py CHANGED
@@ -1,19 +1,16 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
 
4
  """
5
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
  """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
- client = InferenceClient("Qwen/Qwen2.5-VL-3B-Instruct")
9
 
10
  # Use a pipeline as a high-level helper
11
- from transformers import pipeline
12
 
13
  messages = [
14
- {"role": "user", "content": "Who are you?"},
15
  ]
16
- pipe = pipeline("image-text-to-text", model="Qwen/Qwen2.5-VL-7B-Instruct")
17
  pipe(messages)
18
 
19
  def respond(
@@ -24,27 +21,28 @@ def respond(
24
  temperature,
25
  top_p,
26
  ):
27
- messages = [{"role": "system", "content": system_message}]
28
-
29
  for val in history:
30
  if val[0]:
31
- messages.append({"role": "user", "content": val[0]})
32
  if val[1]:
33
- messages.append({"role": "assistant", "content": val[1]})
34
-
35
- messages.append({"role": "user", "content": message})
36
 
 
37
  response = ""
38
-
39
- for message in client.chat_completion(
40
- messages,
41
- max_tokens=max_tokens,
42
- stream=True,
43
  temperature=temperature,
44
  top_p=top_p,
 
 
 
 
45
  ):
46
- token = message.choices[0].delta.content
47
-
48
  response += token
49
  yield response
50
 
@@ -70,4 +68,4 @@ demo = gr.ChatInterface(
70
 
71
 
72
  if __name__ == "__main__":
73
- demo.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
  """
5
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
  """
 
 
7
 
8
  # Use a pipeline as a high-level helper
9
+ pipe = pipeline("text-generation", model="vc3vc3/qwen3-0.6B-finetune")
10
 
11
  messages = [
12
+ {"role": "user", "content": "Who are you? 用中文回答,风格调皮一些。"},
13
  ]
 
14
  pipe(messages)
15
 
16
  def respond(
 
21
  temperature,
22
  top_p,
23
  ):
24
+ # 拼接历史消息和当前消息为 prompt
25
+ prompt = system_message + "\n"
26
  for val in history:
27
  if val[0]:
28
+ prompt += f"用户: {val[0]}\n"
29
  if val[1]:
30
+ prompt += f"助手: {val[1]}\n"
31
+ prompt += f"用户: {message}\n助手:"
 
32
 
33
+ # 使用 pipe 生成回复
34
  response = ""
35
+ for out in pipe(
36
+ prompt,
37
+ max_new_tokens=max_tokens,
 
 
38
  temperature=temperature,
39
  top_p=top_p,
40
+ do_sample=True,
41
+ return_full_text=False,
42
+ truncation=True,
43
+ stream=True,
44
  ):
45
+ token = out["generated_text"] if isinstance(out, dict) and "generated_text" in out else str(out)
 
46
  response += token
47
  yield response
48
 
 
68
 
69
 
70
  if __name__ == "__main__":
71
+ demo.launch()