gaochangkuan commited on
Commit
ad5a269
1 Parent(s): c10c1fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -20
app.py CHANGED
@@ -1,8 +1,12 @@
1
  import os
2
- token = os.getenv('HUGGINGFACE_TOKEN')
3
-
4
  import torch
5
- from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
 
 
 
 
 
 
6
 
7
  model_path= "CubeAI/Zhuji-Internet-Literature-Intelligent-Writing-Model-V1.0"
8
  tokenizer = AutoTokenizer.from_pretrained(model_path, encode_special_tokens=True, token=token)
@@ -19,23 +23,19 @@ model= AutoModelForCausalLM.from_pretrained(
19
  model = torch.compile(model)
20
  model = model.eval()
21
 
22
- import gradio as gr
23
- import os
24
- from transformers import GemmaTokenizer, AutoModelForCausalLM
25
- from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
26
- from threading import Thread
27
 
28
- # Set an environment variable
29
 
30
 
31
 
32
  DESCRIPTION = '''
33
  <div>
34
- <h1 style="text-align: center;">自研模型测试长篇小说概要</h1>
35
- <p>本空间旨在展示我们自行研发的模型在长篇小说领域的应用能力。该模型经过特别优化,适用于长篇小说的生成和理解任务,具备两种不同的规模配置:基础版和高级版。</p>
36
- <p>📚 如果您对模型在长篇小说创作和分析方面的应用感兴趣,欢迎尝试使用我们的基础版模型进行初步探索。</p>
37
- <p>🚀 对于寻求更高级功能和更深层次分析的用户,我们提供了高级版模型,它具备更强大的生成能力和更精细的文本理解技术。</p>
 
38
  </div>
 
39
  '''
40
 
41
  LICENSE = """
@@ -91,14 +91,13 @@ def chat_zhuji(
91
  str: The generated response.
92
  """
93
  conversation = []
94
- #<|system|><|observation|><|user|>
95
  for user, assistant in history:
96
  conversation.extend([{"role": "system","content": "",},{"role": "user", "content": user}, {"role": "<|assistant|>", "content": assistant}])
97
  conversation.append({"role": "user", "content": message})
98
 
99
  input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt").to(model.device)
100
 
101
- streamer = TextIteratorStreamer(tokenizer, timeout=10.0, skip_prompt=True, skip_special_tokens=True)
102
 
103
  generate_kwargs = dict(
104
  input_ids= input_ids,
@@ -128,9 +127,8 @@ def chat_zhuji(
128
  # Gradio block
129
  chatbot=gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
130
  text_box= gr.Textbox(show_copy_button= True)
131
- with gr.Blocks(fill_height=True, css=css) as demo:
132
-
133
- #gr.Markdown(DESCRIPTION)
134
  gr.ChatInterface(
135
  fn=chat_zhuji,
136
  chatbot=chatbot,
@@ -163,9 +161,9 @@ with gr.Blocks(fill_height=True, css=css) as demo:
163
  gr.Markdown(LICENSE)
164
 
165
  if __name__ == "__main__":
166
- demo.launch(
167
  #server_name='0.0.0.0',
168
  #server_port=config.webui_config.port,
169
  #inbrowser=True,
170
- share=True
171
  )
 
1
  import os
 
 
2
  import torch
3
+ import gradio as gr
4
+ from transformers import GemmaTokenizer, AutoModelForCausalLM
5
+ from transformers import AutoModelForCausalLM, AutoConfig, AutoTokenizer, TextIteratorStreamer
6
+ from threading import Thread
7
+
8
+ # Set an environment variable
9
+ token = os.getenv('HUGGINGFACE_TOKEN')
10
 
11
  model_path= "CubeAI/Zhuji-Internet-Literature-Intelligent-Writing-Model-V1.0"
12
  tokenizer = AutoTokenizer.from_pretrained(model_path, encode_special_tokens=True, token=token)
 
23
  model = torch.compile(model)
24
  model = model.eval()
25
 
 
 
 
 
 
26
 
 
27
 
28
 
29
 
30
  DESCRIPTION = '''
31
  <div>
32
+ <h1 style="text-align: center;">网文智能辅助写作 - 珠玑系列模型</h1>
33
+ <p>我们自主研发的珠玑系列智能写作模型,专为网文创作与理解而生。基于丰富的网文场景数据,包括续写、扩写、取名等创作任务和章纲抽取等理解任务,我们训练了一系列模型参数,覆盖1B至14B不等的模型族,包括生成模型和embedding模型。</p>
34
+ <p>📚 <strong>基础版模型:</strong>适合初次尝试智能写作的用户,提供长篇小说创作的基础功能,助您轻松迈入智能写作的新纪元。</p>
35
+ <p>🚀 <strong>高级版模型:</strong>为追求更高层次创作体验的用户设计,配备更先进的文本生成技术和更精细的理解能力,让您的创作更具深度和创新。</p>
36
+ <p>珠玑系列模型(Zhuji-Internet-Literature-Intelligent-Writing-Model-V1.0)现已发布,包括1B、7B、14B规模的模型,基于Qwen1.5架构,旨在为您提供卓越的网文智能写作体验。</p>
37
  </div>
38
+
39
  '''
40
 
41
  LICENSE = """
 
91
  str: The generated response.
92
  """
93
  conversation = []
 
94
  for user, assistant in history:
95
  conversation.extend([{"role": "system","content": "",},{"role": "user", "content": user}, {"role": "<|assistant|>", "content": assistant}])
96
  conversation.append({"role": "user", "content": message})
97
 
98
  input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt").to(model.device)
99
 
100
+ streamer = TextIteratorStreamer(tokenizer, timeout=20.0, skip_prompt=True, skip_special_tokens=True)
101
 
102
  generate_kwargs = dict(
103
  input_ids= input_ids,
 
127
  # Gradio block
128
  chatbot=gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
129
  text_box= gr.Textbox(show_copy_button= True)
130
+ with gr.Blocks(fill_height=True, css=css) as demo:
131
+ gr.Markdown(DESCRIPTION)
 
132
  gr.ChatInterface(
133
  fn=chat_zhuji,
134
  chatbot=chatbot,
 
161
  gr.Markdown(LICENSE)
162
 
163
  if __name__ == "__main__":
164
+ demo.queue().launch(
165
  #server_name='0.0.0.0',
166
  #server_port=config.webui_config.port,
167
  #inbrowser=True,
168
+ #share=True
169
  )