binxu.wang commited on
Commit
48b0464
1 Parent(s): 5c2dae5

add rquirements and models

Browse files
Files changed (2) hide show
  1. app.py +18 -4
  2. requirements.txt +6 -0
app.py CHANGED
@@ -1,9 +1,23 @@
1
  import gradio as gr
2
  import transformers
3
  import tokenizers
 
4
 
5
- def greet(name):
6
- return "Hello " + name + "!!"
 
7
 
8
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
9
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import transformers
3
  import tokenizers
4
+ # https://huggingface.co/docs/hub/spaces-sdks-gradio
5
 
6
+ tokenizer_bert = BertTokenizerFast.from_pretrained('bert-base-chinese',
7
+ additional_special_tokens=["<s>","<pad>","</s>","<unk>","<mask>"],
8
+ pad_token='<pad>' ,max_len=512)
9
 
10
+ configuration = GPT2Config(vocab_size=25000, n_layer=8)
11
+ model = GPT2LMHeadModel(config=configuration)
12
+ #%%
13
+ path2pytorch_model = "pytorch_model.bin"
14
+ model.load_state_dict(torch.load(path2pytorch_model))
15
+
16
+ generator = pipeline('text-generation', model=model, tokenizer=tokenizer_bert)
17
+
18
+ def generate(prompt):
19
+ outputs = generator(prompt, max_length=30, num_return_sequences=5, num_beams=10, top_p=0.999, repetition_penalty=1.5)
20
+ return outputs[0]['generated_text']
21
+
22
+ iface = gr.Interface(fn=generate, inputs="text", outputs="text")
23
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ tqdm
4
+ numpy
5
+ gradio
6
+ tensorboard