Spaces:
Runtime error
Runtime error
File size: 1,616 Bytes
bbdc525 013fbe9 7caf466 013fbe9 5fee423 78cf1f0 013fbe9 5fee423 7caf466 5fee423 013fbe9 40aeecc 013fbe9 5fee423 013fbe9 5fee423 013fbe9 bbdc525 5fee423 013fbe9 5fee423 7caf466 a55ed28 9249236 013fbe9 9e2f3da d499041 5fee423 40aeecc 5fee423 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#TODO: integrate into markdown
import gradio as gr
from gradio import mix
from transformers import pipeline, set_seed
#title = "trustworthy artificial intelligence workshop - content generator"
description = "based on the gpt2 demo interface by <a href='https://huggingface.co/spaces/docs-demos/gpt2/tree/main'>ahsen khaliq</a>"
#io1 = gr.Interface.load("huggingface/distilgpt2")
generator = pipeline('text-generation', model='gpt2')
#io2 = gr.Interface.load("huggingface/gpt2-large")
#io3 = gr.Interface.load("huggingface/gpt2-medium")
#io4 = gr.Interface.load("huggingface/gpt2-xl")
def inference(text, seed):
"""
if model == "gpt2-large":
outtext = io2(text)
elif model == "gpt2-medium":
outtext = io3(text)
elif model == "gpt2-xl":
outtext = io4(text)
else:
outtext = io1(text)
"""
#outtext = io2(text)
set_seed(int(seed))
outtext = generator(text, max_length=100, num_return_sequences=1)['generated_text'] #get the string from the return dict with key 'generated text'
return outtext
gr.Interface(
inference,
[gr.inputs.Radio(choices=["trustworthy artificial intelligence"], label="input"), gr.inputs.Slider(minimum=0., maximum=1000., value=43.,label="seed")],
#,gr.inputs.Dropdown(choices=["distilgpt2","gpt2-medium","gpt2-large","gpt2-xl"], type="value", default="gpt2-medium", label="model")],
gr.outputs.Textbox(label="gpt-2 proposal"),
#title=title,
#description=description,
cache_examples=True).launch(enable_queue=True,
allow_flagging="manual")
#TODO: add credits at bottom |