ysharma HF staff commited on
Commit
be0a1b7
β€’
1 Parent(s): 8ad539d

updated with 8 bit version

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -1,25 +1,34 @@
1
  import gradio as gr
 
2
 
3
- from modelscope.pipelines import pipeline
4
- from modelscope.utils.constant import Tasks
5
 
6
- text_generation_zh = pipeline(task=Tasks.text_generation, model='baichuan-inc/baichuan-7B',model_revision='v1.0.2')
7
- text_generation_zh._model_prepare = True
 
 
 
8
 
9
  def text_generation(input_text):
10
  if input_text == "":
11
  return ""
12
- return text_generation_zh(input_text)['text']
 
 
13
 
14
  with gr.Blocks() as demo:
15
  gr.Markdown(
16
  """
17
- # 百川-7B ζ¨‘εž‹δ½“ιͺŒ
18
  θΎ“ε…₯ζ–‡ζœ¬δ»₯ζŸ₯ηœ‹η”Ÿζˆη»“ζžœγ€‚
 
 
 
19
  """)
20
- inp = gr.Textbox(label="θΎ“ε…₯prompt")
21
- submit = gr.Button("提亀")
22
- out = gr.Textbox(label="η»­ε†™η»“ζžœ")
23
  submit.click(text_generation, inp, out)
24
 
25
  gr.Markdown("## Text Examples")
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
 
4
+ tokenizer = AutoTokenizer.from_pretrained("baichuan-inc/baichuan-7B", trust_remote_code=True)
5
+ model = AutoModelForCausalLM.from_pretrained("baichuan-inc/baichuan-7B", trust_remote_code=True, device_map="auto", load_in_8bit=True)
6
 
7
+ #from transformers import
8
+ #from modelscope.pipelines import pipeline
9
+ #from modelscope.utils.constant import Tasks
10
+ #text_generation_zh = pipeline(task=Tasks.text_generation, model='baichuan-inc/baichuan-7B',model_revision='v1.0.2')
11
+ #text_generation_zh._model_prepare = True
12
 
13
  def text_generation(input_text):
14
  if input_text == "":
15
  return ""
16
+ inputs = tokenizer(input_text, return_tensors='pt').to('cuda:0') #"run->walk\nwrite->"
17
+ pred = model.generate(**inputs, max_new_tokens=64, repetition_penalty=1.1)
18
+ return tokenizer.decode(pred.cpu()[0], skip_special_tokens=True) #text_generation_zh(input_text)['text']
19
 
20
  with gr.Blocks() as demo:
21
  gr.Markdown(
22
  """
23
+ # [Chinese] 百川-7B ζ¨‘εž‹δ½“ιͺŒ
24
  θΎ“ε…₯ζ–‡ζœ¬δ»₯ζŸ₯ηœ‹η”Ÿζˆη»“ζžœγ€‚
25
+
26
+ # [English] Baichuan-7B model experience
27
+ Enter text to see build results.
28
  """)
29
+ inp = gr.Textbox(label="θΎ“ε…₯Prompt / Input Prompt")
30
+ submit = gr.Button("提亀/Submit")
31
+ out = gr.Textbox(label="η»­ε†™η»“ζžœ/Generated Text")
32
  submit.click(text_generation, inp, out)
33
 
34
  gr.Markdown("## Text Examples")