Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,18 +6,20 @@ text_generator = pipeline("text-generation", model="gpt2")
|
|
| 6 |
|
| 7 |
# Define the function for story generation
|
| 8 |
def generate_story(prompt, word_count):
|
|
|
|
|
|
|
| 9 |
# Generate a story based on the user's prompt and word count
|
| 10 |
-
generated_text = text_generator(prompt, max_length=
|
| 11 |
return generated_text
|
| 12 |
|
| 13 |
# Define example inputs for the Gradio interface
|
| 14 |
example_inputs = [
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
]
|
| 22 |
|
| 23 |
# Create a Gradio interface with examples and a word count slider
|
|
@@ -30,8 +32,8 @@ iface = gr.Interface(
|
|
| 30 |
outputs="text",
|
| 31 |
title="Story Generator with Word Count",
|
| 32 |
description="Enter a prompt and select the word count to generate a story.",
|
| 33 |
-
examples=example_inputs
|
| 34 |
)
|
| 35 |
|
| 36 |
# Launch the interface
|
| 37 |
-
iface.launch()
|
|
|
|
| 6 |
|
| 7 |
# Define the function for story generation
|
| 8 |
def generate_story(prompt, word_count):
|
| 9 |
+
# Calculate the maximum length based on word count
|
| 10 |
+
max_length = word_count + len(prompt.split())
|
| 11 |
# Generate a story based on the user's prompt and word count
|
| 12 |
+
generated_text = text_generator(prompt, max_length=max_length, num_return_sequences=1)[0]['generated_text']
|
| 13 |
return generated_text
|
| 14 |
|
| 15 |
# Define example inputs for the Gradio interface
|
| 16 |
example_inputs = [
|
| 17 |
+
"Once upon a time, in a magical forest, there was a curious rabbit named Oliver.",
|
| 18 |
+
"Amidst the hustle and bustle of a busy city, there lived a lonely street musician.",
|
| 19 |
+
"On a distant planet, explorers discovered an ancient alien artifact buried in the sand.",
|
| 20 |
+
"Hidden in the attic of an old house, a forgotten journal revealed a family secret.",
|
| 21 |
+
"In a futuristic world, a brilliant scientist invented a time-traveling device.",
|
| 22 |
+
"Deep in the ocean, an underwater explorer encountered a mysterious and ancient creature."
|
| 23 |
]
|
| 24 |
|
| 25 |
# Create a Gradio interface with examples and a word count slider
|
|
|
|
| 32 |
outputs="text",
|
| 33 |
title="Story Generator with Word Count",
|
| 34 |
description="Enter a prompt and select the word count to generate a story.",
|
| 35 |
+
examples=example_inputs,
|
| 36 |
)
|
| 37 |
|
| 38 |
# Launch the interface
|
| 39 |
+
iface.launch()
|