File size: 896 Bytes
80a9adc b8e372e 80a9adc b8e372e 80a9adc |
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 |
import gradio as gr
from transformers import pipeline
# Create a text-generation pipeline using GPT-2
generator = pipeline('text-generation', model='gpt2')
def generate_text(prompt):
# Adjust temperature to make output more focused
generated = generator(
prompt,
max_length=50,
num_return_sequences=1,
temperature=0.2, # Lower temperature for less randomness
top_k=50, # Optional: limit the number of choices
top_p=0.95 # Optional: nucleus sampling
)
return generated[0]['generated_text']
# Create a Gradio interface with one text input and one text output
iface = gr.Interface(
fn=generate_text,
inputs="text",
outputs="text",
title="Simple LLM with Hugging Face & Gradio",
description="Enter a prompt and get text generated by a basic GPT-2 model."
)
# Launch the interface
iface.launch()
|