saltacc commited on
Commit
7730934
1 Parent(s): fabb1ee

initial commit

Browse files
Files changed (2) hide show
  1. app.py +30 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch.cuda
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+
5
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
6
+
7
+ model = AutoModelForCausalLM.from_pretrained("salt/RandomPrompt-v1")
8
+
9
+ model.to(device)
10
+
11
+ tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-125M")
12
+ tokenizer.pad_token = tokenizer.eos_token
13
+
14
+
15
+ def detect(text_in, max_length):
16
+ if not text_in:
17
+ inputs = tokenizer.pad_token
18
+ else:
19
+ inputs = text_in
20
+ text = tokenizer.batch_decode(model.generate(tokenizer.encode(inputs,
21
+ return_tensors='pt').to(device),
22
+ do_sample=True,
23
+ temperature=0.9,
24
+ max_length=max_length))[0]
25
+ text = text.replace(tokenizer.pad_token, '')
26
+ return text
27
+
28
+
29
+ iface = gr.Interface(fn=detect, inputs=[gr.Textbox(), gr.Slider(50, 200, default=120)], outputs=gr.TextArea())
30
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cu113
2
+ torch
3
+ transformers