Funbi commited on
Commit
8140758
1 Parent(s): ceae2b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -5,19 +5,23 @@ os.system("pip install tensorflow")
5
  os.system("pip install torch")
6
  import gradio as gr
7
 
8
- import tensorflow as tf
9
- from transformers import GPT2LMHeadModel, GPT2Tokenizer, set_seed
10
- tokenizer = GPT2Tokenizer.from_pretrained("gpt2-large")
11
- model = GPT2LMHeadModel.from_pretrained("gpt2-large", pad_token_id=tokenizer.eos_token_id)
12
-
13
-
14
- def generate(prompt,textCount=200):
15
- input_ids = tokenizer.encode(prompt, return_tensors='pt')
16
- if textCount == None or textCount < 200:
17
- textCount=200
18
- # generate text until the output length (which includes the context length) reaches 50
19
- output = model.generate(input_ids, max_length=textCount, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
20
- out = tokenizer.decode(output[0], skip_special_tokens=True)
 
 
 
 
21
  return out
22
 
23
 
@@ -25,7 +29,7 @@ def generate(prompt,textCount=200):
25
  demo = gr.Interface(
26
  fn=generate,
27
  inputs=[gr.Textbox(lines=8, placeholder="Paragraph Here..."),"number"],
28
- outputs="text",title="Text generation app with GPT2",
29
  description="This is a text generation app, it can prove useful when you want to generate texts. All you need to do is copy and paste a short prompt. The potential of this app is limitless especially for writers, you are only limited by your prompt engineering skills",
30
  examples=[
31
  ["During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in"
 
5
  os.system("pip install torch")
6
  import gradio as gr
7
 
8
+ #import tensorflow as tf
9
+ #from transformers import GPT2LMHeadModel, GPT2Tokenizer, set_seed
10
+ #tokenizer = GPT2Tokenizer.from_pretrained("gpt2-large")
11
+ #model = GPT2LMHeadModel.from_pretrained("gpt2-large", pad_token_id=tokenizer.eos_token_id)
12
+
13
+
14
+ from transformers import pipeline
15
+
16
+
17
+
18
+ def generate(prompt,textCount=40):
19
+ if textCount == None or textCount < 40:
20
+ textCount = 40
21
+ generator = pipeline('text-generation', model="facebook/opt-1.3b", do_sample=True, num_return_sequences=3, max_length=textCount)
22
+ out = generator(prompt)
23
+
24
+
25
  return out
26
 
27
 
 
29
  demo = gr.Interface(
30
  fn=generate,
31
  inputs=[gr.Textbox(lines=8, placeholder="Paragraph Here..."),"number"],
32
+ outputs="text",title="Text generation app with Facebook opt",
33
  description="This is a text generation app, it can prove useful when you want to generate texts. All you need to do is copy and paste a short prompt. The potential of this app is limitless especially for writers, you are only limited by your prompt engineering skills",
34
  examples=[
35
  ["During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in"