Spaces:
Sleeping
Sleeping
from transformers import AutoTokenizer, AutoModelForCausalLM | |
import torch | |
import gradio as gr | |
tokenizer = AutoTokenizer.from_pretrained("gpt2-large") | |
model = AutoModelForCausalLM.from_pretrained("Umarpreet/scaryGPT2-large") | |
def text_generation(input_text, seed): | |
input_ids = tokenizer(input_text, return_tensors="pt").input_ids | |
torch.manual_seed(seed) # Max value: 18446744073709551615 | |
outputs = model.generate(input_ids, do_sample=True, min_length=50, max_length=200) | |
generated_text = tokenizer.batch_decode(outputs, skip_special_tokens=True) | |
return generated_text | |
title = "Scary Story Generation" | |
description = "Scary Story Generation using GPT2 by umarpreet" | |
gr.Interface( | |
text_generation, | |
[gr.inputs.Textbox(lines=2, label="Enter starting text"), gr.inputs.Number(default=10, label="Enter seed number")], | |
[gr.outputs.Textbox(type="auto", label="Story Generated")], | |
title=title, | |
description=description, | |
theme="huggingface" | |
).launch() |