BusinessDev's picture
trans
7e21dc1
raw
history blame
809 Bytes
import gradio as gr
from transformers import pipeline
# Load the text generation model
model_id = "gpt2" # You can replace this with any model of your choice
generator = pipeline("text-generation", model=model_id)
# Define the function to process the input and generate text
def generate_text(prompt):
response = generator(prompt, max_length=50, num_return_sequences=1)
generated_text = response[0]['generated_text']
return generated_text
# Create the Gradio interface
iface = gr.Interface(
fn=generate_text,
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
outputs="text",
title="Text Generation",
description="Enter a prompt and the model will generate text based on it."
)
# Launch the interface
if __name__ == "__main__":
iface.launch()