Spaces:
Sleeping
Sleeping
File size: 1,475 Bytes
805f869 305f40f 805f869 305f40f 6cf9cca c238180 305f40f c238180 305f40f |
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 |
import gradio as gr
from transformers import GPT2Tokenizer, GPT2LMHeadModel, pipeline
# Load the model and tokenizer
model_name = "JakeTurner616/Adonalsium-gpt2"
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
model = GPT2LMHeadModel.from_pretrained(model_name)
# Create a pipeline for text generation
text_generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
# Define a function that uses the model to generate text based on the given prompt and parameters
def generate_text(prompt, max_length, temperature, top_p, repetition_penalty):
return text_generator(
prompt,
max_length=max_length,
temperature=temperature,
top_p=top_p,
repetition_penalty=repetition_penalty,
num_return_sequences=1
)[0]['generated_text']
# Create the Gradio interface
iface = gr.Interface(
fn=generate_text,
inputs=[
gr.Textbox(lines=2, label="Input Prompt"),
gr.Slider(minimum=10, maximum=300, step=10, value=100, label="Max Length"),
gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=0.7, label="Temperature"),
gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=0.9, label="Top P"),
gr.Slider(minimum=1.0, maximum=2.0, step=0.1, value=1.1, label="Repetition Penalty"),
],
outputs="text",
title="Cosmere Series Text Generator",
description="Adjust the sliders to control text generation parameters."
)
# Launch the interface
iface.launch() |