File size: 771 Bytes
4974498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d690839
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gpt_2_simple as gpt2
import tensorflow as tf
import gradio as gr

model_name = "124M"

path = 'AbstractGenerator/'
checkpoint_dir =path+'weights/'
data_path = path+'Tokenized_data/'


prefix= '<|startoftext|>'
sufix ='<|endoftext|>'

print("GPU is", "available" if tf.test.is_gpu_available() else "NOT AVAILABLE")


def generateAbstract(text):
    sess = gpt2.start_tf_sess()
    gpt2.load_gpt2(sess,checkpoint_dir=checkpoint_dir,run_name='run1')
    txt = gpt2.generate(sess,prefix=str(text)+"\nABSTRACT", return_as_list=True,truncate=sufix,checkpoint_dir=checkpoint_dir,nsamples=1)[0]
    return str(txt[txt.find('ABSTRACT'):])



iface = gr.Interface(fn=generateAbstract, inputs=gr.inputs.Textbox(lines=10, placeholder="text"), outputs="textbox")
iface.launch()