aliabd HF staff commited on
Commit
6f5b7b7
1 Parent(s): 90fb31f

Upload with huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +1 -2
  2. run.py +21 -0
README.md CHANGED
@@ -6,7 +6,6 @@ colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 3.4.1
9
-
10
- app_file: app.py
11
  pinned: false
12
  ---
6
  colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 3.4.1
9
+ app_file: run.py
 
10
  pinned: false
11
  ---
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()