File size: 2,377 Bytes
e37b309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ff1c2a
83ed340
4ff1c2a
 
 
 
 
ecbc9b9
4ff1c2a
 
 
 
 
 
363ade7
ecbc9b9
33f5db0
de4ff80
ecbc9b9
 
 
 
 
 
fa30377
83ed340
 
6d166ef
372050d
4ff1c2a
 
 
 
6d166ef
83ed340
 
 
 
 
 
 
 
 
4ff1c2a
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

import torch
import RohanGivenCode
from RohanGivenCode import *


save1_or_load0 = 0 # 1 => Save; 0 => Load

device = 'cpu'
if torch.cuda.is_available():
    device = 'cuda'
elif hasattr(torch.backends, "mps") and torch.backends.mps.is_available():
    device = "mps"
print(f"using device: {device}")

# SEED
torch.manual_seed(1337)
if torch.cuda.is_available():
    torch.cuda.manual_seed(1337)

# STOP
# num_return_sequences = 5
# max_length = 30

import gradio as gr
def sentence_builder(new_tokens, ret_seq, txt):
    txt_len = len(txt.split())
    if(txt_len < 9): # To make up minumum requirement of 9 words
        txt += " My lord, I claim your gift, my due by promise"

    t_loader = DataLoaderLite(B = 8, T = 1, text_input = txt)
    out = infer_the_model(device, t_loader, save1_or_load0 = 0, max_length = int(new_tokens), num_return_sequences=int(ret_seq))
    return out


demo = gr.Interface(
    sentence_builder,
    [
        gr.Dropdown(
            ["10", "20", "30", "40", "50", "60", "80", "100"],
            label="Number of New Tokens",
            info="Choose how many tokens are required in output.",
            value="30"
        ),
        gr.Dropdown(
            ["1", "2", "3", "4", "5", "6", "8", "10"],
            label="Number of Return Sequences",
            info="Choose how many return sequences are required in output.",
            value="5"
        ),
        gr.Textbox("", label = "Input",
                   info="Give 8 words atleast, not to get concatenated with default words to make up it's minimum requirement."
                          )
    ],
    [
        gr.Textbox("", label = "Output")
    ],
    title="Shakespeare Drama Dialogue Mimick by GPT3",
    examples=[
               ["30", "5", "A horse! a horse! my kingdom for a horse!"],
               ["30", "5", "What’s In A Name? A Rose By Any Name Would Smell As Sweet"],
               ["30", "5", "If Music Be The Food Of Love, Play On"],
               ["30", "5", "Our Doubts Are Traitors And Make Us Lose The Good We Oft Might Win By Fearing To Attempt."],
               ["30", "5", "All That Glitters Is Not Gold."],
               ["30", "5", "Love All, Trust A Few, Do Wrong To None."],
               ["30", "5", "Love Looks Not With The Eyes, But With The Mind; And Therefore Is Winged Cupid Painted Blind"]
             ]
)

demo.launch(debug=True)