Spaces:
Runtime error
Runtime error
Upload with huggingface_hub
Browse files- DESCRIPTION.md +1 -0
- README.md +1 -1
- app.py +1 -10
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,7 +1,7 @@
|
|
1 |
|
2 |
---
|
3 |
title: autocomplete
|
4 |
-
emoji:
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
|
|
1 |
|
2 |
---
|
3 |
title: autocomplete
|
4 |
+
emoji: 🔥
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
app.py
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
-
# URL: https://huggingface.co/spaces/gradio/autocomplete
|
2 |
-
# DESCRIPTION: 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.
|
3 |
-
# imports
|
4 |
import gradio as gr
|
5 |
import os
|
6 |
|
@@ -11,20 +8,14 @@ auth_token = os.getenv("auth_token")
|
|
11 |
# you can remove the api_key parameter if you don't care about rate limiting.
|
12 |
api = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B", api_key=auth_token)
|
13 |
|
14 |
-
# define the core function
|
15 |
def complete_with_gpt(text):
|
16 |
-
# Use the last 50 characters of the text as context
|
17 |
return text[:-50] + api(text[-50:])
|
18 |
|
19 |
-
# start a block
|
20 |
with gr.Blocks() as demo:
|
21 |
-
# define the UI: one textbox, and a button
|
22 |
textbox = gr.Textbox(placeholder="Type here...", lines=4)
|
23 |
btn = gr.Button("Autocomplete")
|
24 |
|
25 |
-
# define what will run when the button is clicked
|
26 |
-
# the textbox is used as both an input and an output
|
27 |
btn.click(fn=complete_with_gpt, inputs=textbox, outputs=textbox, queue=False)
|
28 |
|
29 |
-
# launch
|
30 |
demo.launch()
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
|
|
|
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()
|