littlebird13 commited on
Commit
777e963
1 Parent(s): 927e513

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -21,14 +21,17 @@ dashscope.api_key = YOUR_API_TOKEN
21
  History = List[Tuple[str, str]]
22
  Messages = List[Dict[str, str]]
23
 
 
24
  def clear_session() -> History:
25
  return '', []
26
 
 
27
  def modify_system_session(system: str) -> str:
28
  if system is None or len(system) == 0:
29
  system = default_system
30
  return system, system, []
31
 
 
32
  def history_to_messages(history: History, system: str) -> Messages:
33
  messages = [{'role': Role.SYSTEM, 'content': system}]
34
  for h in history:
@@ -46,16 +49,17 @@ def messages_to_history(messages: Messages) -> Tuple[str, History]:
46
  return system, history
47
 
48
 
49
- def model_chat(query: Optional[str], history: Optional[History], system: str
50
- ) -> Tuple[str, str, History]:
51
  if query is None:
52
  query = ''
53
  if history is None:
54
  history = []
55
  messages = history_to_messages(history, system)
56
  messages.append({'role': Role.USER, 'content': query})
 
57
  gen = Generation.call(
58
- model = "qwen2.5-coder-32b-instruct",
59
  messages=messages,
60
  result_format='message',
61
  stream=True
@@ -67,13 +71,11 @@ def model_chat(query: Optional[str], history: Optional[History], system: str
67
  system, history = messages_to_history(messages + [{'role': role, 'content': response}])
68
  yield '', history, system
69
  else:
70
- raise HTTPError( code=404, msg='Request id: %s, Status code: %s, error code: %s, error message: %s' % (
71
  response.request_id, response.status_code,
72
  response.code, response.message), hdrs=HTTPMessage(), url='http://example.com', fp=None)
73
 
74
 
75
-
76
-
77
  def chiose_radio(radio, system):
78
  mark_ = gr.Markdown(value=f"<center><font size=8>Qwen2.5-Coder-{radio}-instruct👾</center>")
79
  chatbot = gr.Chatbot(label=f'Qwen2.5-Coder-{radio.lower()}-instruct')
@@ -98,10 +100,10 @@ def main():
98
  # 创建两个标签
99
  with gr.Blocks() as demo:
100
  with gr.Row():
101
- options_coder = ["0.5B", "1.5B", "3B", "7B", "14B", "32B",]
102
  with gr.Row():
103
  radio = gr.Radio(choices=options_coder, label="Qwen2.5-Coder:", value="32B")
104
-
105
  with gr.Row():
106
  with gr.Accordion():
107
  mark_ = gr.Markdown("""<center><font size=8>Qwen2.5-Coder-32B-Instruct Bot👾</center>""")
@@ -119,10 +121,10 @@ def main():
119
  sumbit = gr.Button("🚀 Send")
120
 
121
  textbox.submit(model_chat,
122
- inputs=[textbox, chatbot, system_state],
123
- outputs=[textbox, chatbot, system_input])
124
  sumbit.click(model_chat,
125
- inputs=[textbox, chatbot, system_state],
126
  outputs=[textbox, chatbot, system_input],
127
  concurrency_limit=100)
128
  clear_history.click(fn=clear_session,
 
21
  History = List[Tuple[str, str]]
22
  Messages = List[Dict[str, str]]
23
 
24
+
25
  def clear_session() -> History:
26
  return '', []
27
 
28
+
29
  def modify_system_session(system: str) -> str:
30
  if system is None or len(system) == 0:
31
  system = default_system
32
  return system, system, []
33
 
34
+
35
  def history_to_messages(history: History, system: str) -> Messages:
36
  messages = [{'role': Role.SYSTEM, 'content': system}]
37
  for h in history:
 
49
  return system, history
50
 
51
 
52
+ def model_chat(query: Optional[str], history: Optional[History], system: str, radio: str
53
+ ) -> Tuple[str, str, History]:
54
  if query is None:
55
  query = ''
56
  if history is None:
57
  history = []
58
  messages = history_to_messages(history, system)
59
  messages.append({'role': Role.USER, 'content': query})
60
+ label_model = f"qwen2.5-coder-{radio.lower()}-instruct"
61
  gen = Generation.call(
62
+ model=label_model,
63
  messages=messages,
64
  result_format='message',
65
  stream=True
 
71
  system, history = messages_to_history(messages + [{'role': role, 'content': response}])
72
  yield '', history, system
73
  else:
74
+ raise HTTPError(code=404, msg='Request id: %s, Status code: %s, error code: %s, error message: %s' % (
75
  response.request_id, response.status_code,
76
  response.code, response.message), hdrs=HTTPMessage(), url='http://example.com', fp=None)
77
 
78
 
 
 
79
  def chiose_radio(radio, system):
80
  mark_ = gr.Markdown(value=f"<center><font size=8>Qwen2.5-Coder-{radio}-instruct👾</center>")
81
  chatbot = gr.Chatbot(label=f'Qwen2.5-Coder-{radio.lower()}-instruct')
 
100
  # 创建两个标签
101
  with gr.Blocks() as demo:
102
  with gr.Row():
103
+ options_coder = ["0.5B", "1.5B", "3B", "7B", "14B", "32B", ]
104
  with gr.Row():
105
  radio = gr.Radio(choices=options_coder, label="Qwen2.5-Coder:", value="32B")
106
+
107
  with gr.Row():
108
  with gr.Accordion():
109
  mark_ = gr.Markdown("""<center><font size=8>Qwen2.5-Coder-32B-Instruct Bot👾</center>""")
 
121
  sumbit = gr.Button("🚀 Send")
122
 
123
  textbox.submit(model_chat,
124
+ inputs=[textbox, chatbot, system_state, radio],
125
+ outputs=[textbox, chatbot, system_input])
126
  sumbit.click(model_chat,
127
+ inputs=[textbox, chatbot, system_state, radio],
128
  outputs=[textbox, chatbot, system_input],
129
  concurrency_limit=100)
130
  clear_history.click(fn=clear_session,