BigSalmon commited on
Commit
04120c9
1 Parent(s): b22819a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import (
2
+ AutoTokenizer,
3
+ AutoModelForCausalLM,
4
+ GPTNeoForCausalLM,
5
+ )
6
+ import torch
7
+ import psutil
8
+ tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-2.7B")
9
+ model = AutoModelForCausalLM.from_pretrained("NovelAI/genji-python-6B").half().eval().cuda()
10
+ import gradio as gr
11
+ top_k = 50
12
+ repetition_penalty = 1.13
13
+ repetition_penalty_range = 512
14
+ repetition_penalty_slope = 3.33
15
+ def generator(text, temperature ,top_p, maxLength):
16
+ tokens = tokenizer(text, return_tensors="pt").input_ids.cuda()[:, -(1500-maxLength):]
17
+ out = model.generate(
18
+ tokens.long(),
19
+ do_sample=True,
20
+ min_length=tokens.shape[1] + maxLength,
21
+ max_length=tokens.shape[1] + maxLength,
22
+ temperature=temperature,
23
+ top_k = top_k,
24
+ top_p = top_p,
25
+ repetition_penalty = repetition_penalty,
26
+ repetition_penalty_range = repetition_penalty_range,
27
+ repetition_penalty_slope = repetition_penalty_slope,
28
+ use_cache=True,
29
+ bad_words_ids=None,
30
+ pad_token_id=tokenizer.eos_token_id,
31
+ ).long().to("cpu")[0]
32
+ return tokenizer.decode(out[tokens.shape[1]:])
33
+ title = "genji-python-6b"
34
+ description = "Gradio demo for Genji-python-6b: Genji is a transformer model finetuned on EleutherAI's GPT-J 6B model. This particular model is trained on python only code approaching 4GB in size. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
35
+ article = "<p style='text-align: center'><a href='https://colab.research.google.com/drive/1PnWpx02IEUkY8jhLKd_NewUGEXahAska'>Colab</a> | <a href='https://huggingface.co/NovelAI/genji-python-6B'>Huggingface Model</a></p>"
36
+ gr.Interface(
37
+ generator,
38
+ [gr.inputs.Textbox(label="input text", lines=5),
39
+ gr.inputs.Slider(minimum=0.1, maximum=1.0, step=0.1, default=0.2, label="Temperature"),
40
+ gr.inputs.Slider(minimum=0.0, maximum=1.0, step=0.1, default=1.0, label="Top P"),
41
+ gr.inputs.Slider(minimum=1, maximum=400, step=1, default=200, label="Max Length")
42
+ ],
43
+ gr.outputs.Textbox(label="Output text"),
44
+ title=title,
45
+ description=description,
46
+ article=article,
47
+ examples=[
48
+ ['def print_Hello_Huggingface():', 0.2, 1.0,200]
49
+ ]).launch(debug=True)