Spaces:
Runtime error
Runtime error
Ahsen Khaliq
commited on
Commit
·
431d650
1
Parent(s):
aed9b23
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
10 |
+
model = AutoModelForCausalLM.from_pretrained("NovelAI/genji-python-6B").half().eval().cuda()
|
11 |
+
|
12 |
+
import gradio as gr
|
13 |
+
|
14 |
+
maxLength=200
|
15 |
+
temperature=0.4
|
16 |
+
top_k = 50
|
17 |
+
top_p = 0.9
|
18 |
+
repetition_penalty = 1.13
|
19 |
+
repetition_penalty_range = 512
|
20 |
+
repetition_penalty_slope = 3.33
|
21 |
+
def generator(text):
|
22 |
+
tokens = tokenizer(text, return_tensors="pt").input_ids.cuda()[:, -(2047-maxLength):]
|
23 |
+
out = model.generate(
|
24 |
+
tokens.long(),
|
25 |
+
do_sample=True,
|
26 |
+
min_length=tokens.shape[1] + maxLength,
|
27 |
+
max_length=tokens.shape[1] + maxLength,
|
28 |
+
temperature=temperature,
|
29 |
+
top_k = top_k,
|
30 |
+
top_p = top_p,
|
31 |
+
repetition_penalty = repetition_penalty,
|
32 |
+
repetition_penalty_range = repetition_penalty_range,
|
33 |
+
repetition_penalty_slope = repetition_penalty_slope,
|
34 |
+
use_cache=True,
|
35 |
+
bad_words_ids=None,
|
36 |
+
pad_token_id=tokenizer.eos_token_id,
|
37 |
+
).long().to("cpu")[0]
|
38 |
+
return tokenizer.decode(out[tokens.shape[1]:])
|
39 |
+
|
40 |
+
title = "genji-python-6b"
|
41 |
+
description = "demo for Genji-python-6b. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
|
42 |
+
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>"
|
43 |
+
|
44 |
+
gr.Interface(
|
45 |
+
generator,
|
46 |
+
[gr.inputs.Textbox(label="input text")],
|
47 |
+
gr.outputs.Textbox(label="Output text"),
|
48 |
+
title=title,
|
49 |
+
description=description,
|
50 |
+
article=article,
|
51 |
+
examples=[
|
52 |
+
['def print_customer_name']
|
53 |
+
]).launch(debug=True)
|