aliabd HF staff commited on
Commit
3b2d88c
1 Parent(s): d1844e0

Upload with huggingface_hub

Browse files
Files changed (4) hide show
  1. DESCRIPTION.md +1 -0
  2. README.md +6 -7
  3. requirements.txt +3 -0
  4. run.py +22 -0
DESCRIPTION.md ADDED
@@ -0,0 +1 @@
 
 
1
+ This text generation demo takes in input text and returns generated text. It uses the Transformers library to set up the model and has two examples.
README.md CHANGED
@@ -1,12 +1,11 @@
 
1
  ---
2
- title: Text Generation Main
3
- emoji: 🌖
4
- colorFrom: purple
5
- colorTo: gray
6
  sdk: gradio
7
  sdk_version: 3.6
8
- app_file: app.py
9
  pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: text_generation_main
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 3.6
9
+ app_file: run.py
10
  pinned: false
11
  ---
 
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ git+https://github.com/huggingface/transformers
2
+ gradio
3
+ torchhttps://gradio-main-build.s3.amazonaws.com/c3bec6153737855510542e8154391f328ac72606/gradio-3.6-py3-none-any.whl
run.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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=30, num_return_sequences=1)
8
+ return result[0]["generated_text"]
9
+
10
+ examples = [
11
+ ["The Moon's orbit around Earth has"],
12
+ ["The smooth Borealis basin in the Northern Hemisphere covers 40%"],
13
+ ]
14
+
15
+ demo = gr.Interface(
16
+ fn=generate,
17
+ inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
18
+ outputs=gr.outputs.Textbox(label="Generated Text"),
19
+ examples=examples
20
+ )
21
+
22
+ demo.launch()