File size: 1,579 Bytes
380455d
 
 
 
a36c73f
380455d
 
8140758
 
 
 
 
 
 
 
 
 
 
 
 
4707bee
8140758
9ee0429
8140758
 
9ee0429
380455d
 
 
 
 
 
8140758
3cad11a
380455d
 
ceae2b2
380455d
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
os.system("pip install transformers")
os.system("pip install gradio")
os.system("pip install tensorflow")
os.system("pip install torch")
import gradio as gr

#import tensorflow as tf
#from transformers import GPT2LMHeadModel, GPT2Tokenizer, set_seed
#tokenizer = GPT2Tokenizer.from_pretrained("gpt2-large")
#model = GPT2LMHeadModel.from_pretrained("gpt2-large", pad_token_id=tokenizer.eos_token_id)


from transformers import pipeline



def generate(prompt,textCount=40):
    if textCount == None or textCount < 40:
        textCount = 40
    generator = pipeline('text-generation', model="facebook/opt-1.3b", do_sample=True, num_return_sequences=2, max_length=textCount)
    out = generator(prompt)
    bout = f"{out[0]['generated_text']} \n {out[1]['generated_text']}"
    

    return bout



demo = gr.Interface(
    fn=generate,
    inputs=[gr.Textbox(lines=8, placeholder="Paragraph Here..."),"number"],
    outputs="text",title="Text generation app with Facebook opt",
    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",
    examples=[
        ["During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in"
],["Question: What hurdles or challenges are you facing as you move through your career journey? Please share a specific example?answer:I have been"]
    ],
)
demo.launch()