NadaAljohani's picture
Update app.py
5d6eedb verified
raw
history blame
No virus
1.42 kB
import gradio as gr
from transformers import pipeline
# Function to generate the story
def generate_story(title, model_name):
# Use text-generation pipeline from Hugging Face
generator = pipeline('text-generation', model=model_name)
# Generate the story based on the input title
story = generator(title,
max_length=200, # Fixed max length for the story
temperature=0.7, # Fixed temperature for some randomness
num_return_sequences=1)
# Return the generated text
return story[0]['generated_text']
# Create the Gradio interface using gr.Interface
demo = gr.Interface(
fn=generate_story, # The function to run
inputs=[ # Inputs for the interface
gr.Textbox(label="Enter Story Title", placeholder="Type a title here..."), # Title input
gr.Dropdown(choices=['gpt2', 'gpt2-medium', 'gpt2-large', 'EleutherAI/gpt-neo-2.7B', 'EleutherAI/gpt-j-6B','maldv/badger-writer-llama-3-8b'],
value='gpt2',
label="Choose Model") # Model selection input
],
outputs=gr.Textbox(label="Generated Story", lines=10), # Output for the generated story
title="AI Story Generator", # Title of the interface
description="Enter a title and choose a model to generate a short story" # A short description
)
# Launch the interface
demo.launch(share=True)