File size: 1,012 Bytes
46f5a0c
 
 
acf366c
46f5a0c
 
acf366c
 
46f5a0c
 
 
198e2c6
acf366c
198e2c6
acf366c
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

generator = pipeline('text-generation', model='gpt2')

def text_generator(sample, max_length):
    outputs = generator(sample, max_length=int(max_length), num_return_sequences=3)
    return outputs[0]["generated_text"], outputs[1]["generated_text"], outputs[2]["generated_text"]

examples = [["Hello, I'm a language model", "45"], ["Hello, I'm a designer", "30"]]

css = """
# CSS content as before
"""

# Modify the demo.launch call to include the api_name parameter
demo = gr.Interface(
    fn=text_generator,
    inputs=[gr.Textbox(lines=2, placeholder="Enter sample text here", label="Sample text"), gr.Textbox(lines=1, label="Length of generated text")],
    outputs=[gr.Textbox(label="Generated text 1"), gr.Textbox(label="Generated text 2"), gr.Textbox(label="Generated text 3")],
    title="Text Generator | Data Science Dojo",
    examples=examples,
    css=css
)

# Launch with api_name specified
demo.launch(debug=True, api_name="generate_text")