|
import gradio as gr |
|
from transformers import pipeline, set_seed |
|
|
|
generator = pipeline('text-generation', model='flax-community/miniLM-L6-h384-uncased', device=0) |
|
|
|
def generate_text(prompt, length=50, temperature=0.7, seed=42): |
|
set_seed(seed) |
|
output = generator(prompt, max_length=length, do_sample=True, temperature=temperature) |
|
return output[0]['generated_text'] |
|
|
|
inputs = gr.inputs.Textbox(lines=5, label="Prompt") |
|
outputs = gr.outputs.Textbox(label="Output Text") |
|
temperature_slider = gr.inputs.Slider(minimum=0.1, maximum=1.5, default=0.7, label="Temperature") |
|
length_slider = gr.inputs.Slider(minimum=10, maximum=200, default=50, label="Length") |
|
seed_input = gr.inputs.Number(default=42, label="Seed") |
|
|
|
gr.Interface(fn=generate_text, inputs=[inputs, length_slider, temperature_slider, seed_input], outputs=outputs, title="Generative AI", description="Use MiniLM to generate text based on a prompt.").launch() |
|
|