File size: 2,101 Bytes
2afe341
71a48d6
2e92b1f
 
 
 
 
 
 
 
 
 
 
 
 
71a48d6
2afe341
 
 
2e92b1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
810185a
2e92b1f
 
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
41
42
43
44
45
#import libraries and dependencies
import gradio as gr
from gradio.mix import Parallel

#instantiate variables as strings
title="Text Generators"
description="Select a text generator from the tabs below."
description1="This is the basic text generator all students were taught to code using an older, smaller language model. Input text, submit, and the text generator will generate one output text instance."
description2="This is a more advanced text generator that many students were taught to code. Input text and the text generator generates three output text instances from three language models. Importantly, two of these language models were designed to process explicit instructions."
examples = [
    ["Zoe Kwan is a 20-year old singer and songwriter who has taken Hong Kong’s music scene by storm."],
    ["What is this life for?"],
    ["Write a story that begins, 'Once upon a time, '"]
    ["What is the best way to start a short story?"]
]

#instantiate variables as functions
model1 = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B")
model2 = gr.Interface.load("huggingface/google/flan-t5-xl")
model3 = gr.Interface.load("huggingface/bigscience/bloomz-560m")
model4 = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B")

#decapoda-research/llama-7b-hf
#define functions
def complete_with_gpt(text):
    # Use the last 50 characters of the text as context
    return text[:-50] + model4(text[-50:])

with gr.Blocks() as demo:
    with gr.Row():
        textbox = gr.Textbox(placeholder="Type here and press enter...", lines=8)
        with gr.Column():
            btn = gr.Button("Generate")

    btn.click(complete_with_gpt, textbox, textbox)

tab1 = gr.Interface.load("huggingface/gpt2", description=description1)
tab2 = gr.Paralle(model1, model2, model3, inputs=gr.Textbox(lines=5, label="Input explicit or implicit instructions"), description=description2, examples=examples)
tab3 = demo.launch()

demo1 = gr.TabbedInterface([tab1, tab2, tab3], ["Level 1", "Level 3", "Level 5"], title=title, description=description)

if __name__ == "__main__":
    demo1.launch(debug=True)