aliabd HF staff commited on
Commit
8469365
1 Parent(s): 3a3a352

Create new file

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # URL: https://huggingface.co/spaces/gradio/text_generation
2
+ # imports
3
+ import gradio as gr
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM
5
+ import torch
6
+
7
+ # loading the model
8
+ tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-j-6B")
9
+ model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-j-6B")
10
+
11
+ # defining the core function
12
+ def generate(text):
13
+ generation_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
14
+ result = generation_pipeline(text)
15
+ return result[0]["generated_text"]
16
+
17
+
18
+ # defining title, description and examples
19
+ title = "Text Generation with GPT-J-6B"
20
+ description = "This demo generates text using GPT-J 6B: a transformer model trained using Ben Wang's Mesh Transformer JAX."
21
+ examples = [
22
+ ["The Moon's orbit around Earth has"],
23
+ ["The smooth Borealis basin in the Northern Hemisphere covers 40%"],
24
+ ]
25
+
26
+ # defining the interface
27
+ demo = gr.Interface(
28
+ fn=generate,
29
+ inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
30
+ outputs=gr.outputs.Textbox(label="Generated Text"),
31
+ title=title,
32
+ description=description,
33
+ examples=examples,
34
+ )
35
+
36
+ # launching
37
+ demo.launch()