Spaces:
No application file
No application file
Create AI Based Story Teller
Browse files- AI Based Story Teller +34 -0
AI Based Story Teller
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pip install transformers gradio
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# Load the GPT model for text generation
|
| 6 |
+
generator = pipeline('text-generation', model='gpt-3.5-turbo')
|
| 7 |
+
|
| 8 |
+
# Define the function to generate a story
|
| 9 |
+
def generate_story(genre, prompt):
|
| 10 |
+
if genre == "Fantasy":
|
| 11 |
+
prompt = f"A fantasy story about {prompt}."
|
| 12 |
+
elif genre == "Sci-Fi":
|
| 13 |
+
prompt = f"A science fiction story about {prompt}."
|
| 14 |
+
elif genre == "Romance":
|
| 15 |
+
prompt = f"A romantic story about {prompt}."
|
| 16 |
+
else:
|
| 17 |
+
prompt = f"A story about {prompt}."
|
| 18 |
+
|
| 19 |
+
story = generator(prompt, max_length=500, num_return_sequences=1)[0]['generated_text']
|
| 20 |
+
return story
|
| 21 |
+
|
| 22 |
+
# Create the Gradio interface
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=generate_story,
|
| 25 |
+
inputs=[
|
| 26 |
+
gr.Dropdown(choices=["Fantasy", "Sci-Fi", "Romance", "Mystery"], label="Select Genre"),
|
| 27 |
+
gr.Textbox(label="Enter a prompt", placeholder="Enter a theme, character name, etc."),
|
| 28 |
+
],
|
| 29 |
+
outputs=gr.Textbox(label="Generated Story"),
|
| 30 |
+
live=True
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Launch the interface
|
| 34 |
+
iface.launch()
|