aliabd HF staff commited on
Commit
939fc87
·
1 Parent(s): c0f92bf

Upload with huggingface_hub

Browse files
Files changed (4) hide show
  1. DESCRIPTION.md +1 -0
  2. README.md +6 -7
  3. requirements.txt +1 -0
  4. run.py +21 -0
DESCRIPTION.md ADDED
@@ -0,0 +1 @@
 
 
1
+ This text generation demo works like autocomplete. There's only one textbox and it's used for both the input and the output. The demo loads the model as an interface, and uses that interface as an API. It then uses blocks to create the UI. All of this is done in less than 10 lines of code.
README.md CHANGED
@@ -1,12 +1,11 @@
 
1
  ---
2
- title: Autocomplete Main
3
- emoji: 👁
4
- colorFrom: green
5
- colorTo: green
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: autocomplete_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 @@
 
 
1
+ https://gradio-main-build.s3.amazonaws.com/c3bec6153737855510542e8154391f328ac72606/gradio-3.6-py3-none-any.whl
run.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ # save your HF API token from https:/hf.co/settings/tokens as an env variable to avoid rate limiting
5
+ auth_token = os.getenv("auth_token")
6
+
7
+ # load a model from https://hf.co/models as an interface, then use it as an api
8
+ # you can remove the api_key parameter if you don't care about rate limiting.
9
+ api = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B", api_key=auth_token)
10
+
11
+ def complete_with_gpt(text):
12
+ return text[:-50] + api(text[-50:])
13
+
14
+ with gr.Blocks() as demo:
15
+ textbox = gr.Textbox(placeholder="Type here...", lines=4)
16
+ btn = gr.Button("Autocomplete")
17
+
18
+ # define what will run when the button is clicked, here the textbox is used as both an input and an output
19
+ btn.click(fn=complete_with_gpt, inputs=textbox, outputs=textbox, queue=False)
20
+
21
+ demo.launch()