Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,33 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load the
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
story += "Once upon a time..."
|
25 |
-
|
26 |
-
return story
|
27 |
-
|
28 |
-
# Define example inputs for the interface
|
29 |
-
example_inputs = ["I love ice cream",
|
30 |
-
"Tell me about Apple Inc.",
|
31 |
-
"Explain the concept of quantum physics",
|
32 |
-
"What is the capital of France?",
|
33 |
-
"Who is the CEO of Microsoft?",
|
34 |
-
"What is the population of New York City?"]
|
35 |
-
|
36 |
-
# Create the Gradio interface with examples
|
37 |
iface = gr.Interface(
|
38 |
fn=generate_story,
|
39 |
-
inputs=
|
40 |
-
outputs=
|
41 |
-
|
|
|
42 |
examples=example_inputs,
|
43 |
-
title="Interactive Story Generator",
|
44 |
-
description="Enter your input, and we will generate an interactive story for you."
|
45 |
)
|
46 |
|
47 |
# Launch the interface
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load the text generation model
|
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=200, num_return_sequences=1)[0]['generated_text']
|
11 |
+
return generated_text
|
12 |
+
|
13 |
+
# Define example inputs for the Gradio interface
|
14 |
+
example_inputs = [
|
15 |
+
"Once upon a time, there was a young boy who lived in a small village.",
|
16 |
+
"The sun was setting over the horizon, casting a warm glow over the city.",
|
17 |
+
"In a galaxy far, far away, a group of rebels were planning their next move.",
|
18 |
+
"The door creaked open, revealing a dark and mysterious room.",
|
19 |
+
"The clock struck midnight, and the old house came to life.",
|
20 |
+
"The wind howled through the trees, as the storm raged on."
|
21 |
+
]
|
22 |
+
|
23 |
+
# Create a Gradio interface with examples
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
iface = gr.Interface(
|
25 |
fn=generate_story,
|
26 |
+
inputs="text",
|
27 |
+
outputs="text",
|
28 |
+
title="Story Generator",
|
29 |
+
description="Enter a prompt to generate a story.",
|
30 |
examples=example_inputs,
|
|
|
|
|
31 |
)
|
32 |
|
33 |
# Launch the interface
|