DGRDN commited on
Commit
f3d703a
·
verified ·
1 Parent(s): 437c508

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load a storytelling model
5
+ story_gen = pipeline("text-generation", model="gpt2")
6
+
7
+ def generate_story(prompt):
8
+ try:
9
+ story = story_gen(prompt, max_length=300, do_sample=True, temperature=0.9)[0]["generated_text"]
10
+ return story
11
+ except Exception as e:
12
+ return f"⚠️ Error: {str(e)}"
13
+
14
+ demo = gr.Interface(
15
+ fn=generate_story,
16
+ inputs=gr.Textbox(lines=2, placeholder="Enter a story prompt..."),
17
+ outputs=gr.Textbox(lines=15, label="📖 Your AI-generated story"),
18
+ title="📝 Narrative Generator",
19
+ description="Enter a prompt and let the AI write a story for you!"
20
+ )
21
+
22
+ demo.launch()