Wootang01 commited on
Commit
70865a3
1 Parent(s): d25b67e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -1,18 +1,20 @@
 
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- generator = pipeline('text-generation', model='gpt2')
5
 
6
- def generate(text):
7
- result = generator(text, max_length=100, num_return_sequences=3)
8
- return result[0]["generated_text"]
9
 
10
- examples = [
11
- ["Zoe Kwan is a 20-year old singer and songwriter who has taken Hong Kong’s music scene by storm."],
12
- ["Zoe only recently began writing songs."],
13
- ]
14
 
15
- demo = gr.Interface(fn=generate, inputs=gr.inputs.Textbox(lines=5, label="Input Text"), outputs=gr.outputs.Textbox(label="Generated Text"),
16
- title='Text Generator GPT2', examples=examples)
 
 
 
 
 
 
17
 
18
  demo.launch()
 
1
+ #level 5 text generator
2
  import gradio as gr
 
3
 
4
+ api = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B")
5
 
 
 
 
6
 
7
+ def complete_with_gpt(text):
8
+ # Use the last 50 characters of the text as context
9
+ return text[:-50] + api(text[-50:])
 
10
 
11
+
12
+ with gr.Blocks() as demo:
13
+ with gr.Row():
14
+ textbox = gr.Textbox(placeholder="Type here and press enter...", lines=4)
15
+ with gr.Column():
16
+ btn = gr.Button("Generate")
17
+
18
+ btn.click(complete_with_gpt, textbox, textbox)
19
 
20
  demo.launch()