Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,9 +5,9 @@ from transformers import pipeline
|
|
| 5 |
text_generator = pipeline("text-generation", model="gpt2")
|
| 6 |
|
| 7 |
# Define the function for story generation
|
| 8 |
-
def generate_story(prompt):
|
| 9 |
-
# Generate a story based on the user's prompt
|
| 10 |
-
generated_text = text_generator(prompt, max_length=
|
| 11 |
return generated_text
|
| 12 |
|
| 13 |
# Define example inputs for the Gradio interface
|
|
@@ -20,13 +20,16 @@ example_inputs = [
|
|
| 20 |
"Deep in the ocean, an underwater explorer encountered a mysterious and ancient creature."
|
| 21 |
]
|
| 22 |
|
| 23 |
-
# Create a Gradio interface with examples
|
| 24 |
iface = gr.Interface(
|
| 25 |
fn=generate_story,
|
| 26 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
| 27 |
outputs="text",
|
| 28 |
-
title="Story Generator",
|
| 29 |
-
description="Enter a prompt to generate a story.",
|
| 30 |
examples=example_inputs
|
| 31 |
)
|
| 32 |
|
|
|
|
| 5 |
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=word_count, num_return_sequences=1)[0]['generated_text']
|
| 11 |
return generated_text
|
| 12 |
|
| 13 |
# Define example inputs for the Gradio interface
|
|
|
|
| 20 |
"Deep in the ocean, an underwater explorer encountered a mysterious and ancient creature."
|
| 21 |
]
|
| 22 |
|
| 23 |
+
# Create a Gradio interface with examples and a word count slider
|
| 24 |
iface = gr.Interface(
|
| 25 |
fn=generate_story,
|
| 26 |
+
inputs=[
|
| 27 |
+
gr.components.Textbox(label="Prompt"),
|
| 28 |
+
gr.components.Slider(minimum=50, maximum=500, default=100, label="Word Count")
|
| 29 |
+
],
|
| 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 |
|