CMLL commited on
Commit
7463509
·
verified ·
1 Parent(s): 6d70e26

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -29
app.py CHANGED
@@ -21,21 +21,6 @@ tokenizer = AutoTokenizer.from_pretrained(
21
  pad_token=''
22
  )
23
 
24
- #单轮
25
- @spaces.GPU
26
- def single_turn_chat(question):
27
- prompt = f"Question: {question}"
28
- messages = [
29
- {"role": "system", "content": "You are a helpful TCM medical assistant named 仲景中医大语言模型, created by 医哲未来 of Fudan University."},
30
- {"role": "user", "content": prompt}
31
- ]
32
- input = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
33
- model_inputs = tokenizer([input], return_tensors="pt").to(device)
34
- generated_ids = model.generate( model_inputs.input_ids,max_new_tokens=512)
35
- generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
36
- response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
37
- return response
38
-
39
  #多轮
40
  @spaces.GPU
41
  def multi_turn_chat(question, chat_history=None):
@@ -80,15 +65,6 @@ def multi_turn_chat(question, chat_history=None):
80
  def clear_history():
81
  return [], []
82
 
83
- # 单轮界面
84
- single_turn_interface = gr.Interface(
85
- fn=single_turn_chat,
86
- inputs=["text"],
87
- outputs="text",
88
- title="仲景GPT-V2-1.8B 单轮对话",
89
- description="博极医源,精勤不倦。Unlocking the Wisdom of Traditional Chinese Medicine with AI."
90
- )
91
-
92
  # 多轮界面
93
  multi_turn_interface = gr.Interface(
94
  lambda x, y: multi_turn_chat(x, y)[0],
@@ -98,8 +74,4 @@ multi_turn_interface = gr.Interface(
98
  allow_flagging="never",
99
  )
100
 
101
- # 组合单轮和多轮界面
102
- main_ui = gr.TabbedInterface([single_turn_interface, multi_turn_interface], ["单轮对话", "多轮对话"])
103
-
104
- # 启动界面
105
- main_ui.launch(debug=True, server_name='0.0.0.0', server_port=6006)
 
21
  pad_token=''
22
  )
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  #多轮
25
  @spaces.GPU
26
  def multi_turn_chat(question, chat_history=None):
 
65
  def clear_history():
66
  return [], []
67
 
 
 
 
 
 
 
 
 
 
68
  # 多轮界面
69
  multi_turn_interface = gr.Interface(
70
  lambda x, y: multi_turn_chat(x, y)[0],
 
74
  allow_flagging="never",
75
  )
76
 
77
+ multi_turn_interface.queue(concurrency_count=10, max_size=20).launch(debug=True, server_name='0.0.0.0', server_port=6006)