raja5259 commited on
Commit
4ff1c2a
·
verified ·
1 Parent(s): 15e9006

create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import torch
3
+ import RohanGivenCode
4
+ from RohanGivenCode import *
5
+
6
+
7
+ save1_or_load0 = 0 # 1 => Save; 0 => Load
8
+
9
+ device = 'cpu'
10
+ if torch.cuda.is_available():
11
+ device = 'cuda'
12
+ elif hasattr(torch.backends, "mps") and torch.backends.mps.is_available():
13
+ device = "mps"
14
+ print(f"using device: {device}")
15
+
16
+ # SEED
17
+ torch.manual_seed(1337)
18
+ if torch.cuda.is_available():
19
+ torch.cuda.manual_seed(1337)
20
+
21
+ # STOP
22
+ num_return_sequences = 5
23
+ max_length = 30
24
+
25
+
26
+ import gradio as gr
27
+ def sentence_builder(txt):
28
+ txt_len = len(txt.split())
29
+ if(txt_len < 9): # To make up minumum requirement of 9 words
30
+ txt += " My lord, I claim your gift, my due by promise"
31
+
32
+ t_loader = DataLoaderLite(B = 8, T = 1, text_input = txt)
33
+ out = infer_the_model(device, t_loader, save1_or_load0 = 0)
34
+ return out
35
+
36
+
37
+ demo = gr.Interface(
38
+ sentence_builder,
39
+ [
40
+ gr.Textbox("", label = "Input", info="Give 8 words atleast, not to get concatenated with default words to make up it's minimum requirement.")
41
+ ],
42
+ [
43
+ gr.Textbox("", label = "Output")
44
+ ],
45
+ title="Shakespeare Drama Dialogue Mimick by GPT3"
46
+ )
47
+
48
+ demo.launch(debug=True)