Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,42 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
)
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio import mix
|
3 |
+
|
4 |
+
title = "GPT2"
|
5 |
+
description = "Gradio Demo for OpenAI GPT2. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
|
6 |
+
|
7 |
+
article = "<p style='text-align: center'><a href='https://d4mucfpksywv.cloudfront.net/better-language-models/language_models_are_unsupervised_multitask_learners.pdf' target='_blank'>Language Models are Unsupervised Multitask Learners</a></p>"
|
8 |
+
|
9 |
+
examples = [
|
10 |
+
['Paris is the capital of',"gpt2-medium"]
|
11 |
+
]
|
12 |
+
|
13 |
+
io1 = gr.Interface.load("huggingface/distilgpt2")
|
14 |
+
|
15 |
+
io2 = gr.Interface.load("huggingface/gpt2-large")
|
16 |
+
|
17 |
+
io3 = gr.Interface.load("huggingface/gpt2-medium")
|
18 |
+
|
19 |
+
io4 = gr.Interface.load("huggingface/gpt2-xl")
|
20 |
+
|
21 |
+
def inference(text, model):
|
22 |
+
if model == "gpt2-large":
|
23 |
+
outtext = io2(text)
|
24 |
+
elif model == "gpt2-medium":
|
25 |
+
outtext = io3(text)
|
26 |
+
elif model == "gpt2-xl":
|
27 |
+
outtext = io4(text)
|
28 |
+
else:
|
29 |
+
outtext = io1(text)
|
30 |
+
return outtext
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
gr.Interface(
|
35 |
+
inference,
|
36 |
+
[gr.inputs.Textbox(label="Input"),gr.inputs.Dropdown(choices=["distilgpt2","gpt2-medium","gpt2-large","gpt2-xl"], type="value", default="gpt2-medium", label="model")
|
37 |
+
],
|
38 |
+
gr.outputs.Textbox(label="Output"),
|
39 |
+
examples=examples,
|
40 |
+
article=article,
|
41 |
+
title=title,
|
42 |
+
description=description).launch(enable_queue=True)
|