Spaces:
Sleeping
Sleeping
Leo Liu
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -10,8 +10,21 @@ def img2text(url):
|
|
10 |
return text
|
11 |
|
12 |
# text2story
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def text2story(text):
|
14 |
-
story_text = pipeline("text-generation", model="distilbert/distilgpt2"
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
return story_text
|
16 |
|
17 |
# text2audio
|
|
|
10 |
return text
|
11 |
|
12 |
# text2story
|
13 |
+
story_prompt = (
|
14 |
+
f"You are an expert in storytelling for children ages 3-10."
|
15 |
+
f"Based on the image description below:{text}\n"
|
16 |
+
f"Please create a funny, heartwarming, imaginative fairy tale of no less than 50 words"
|
17 |
+
f"Output only the body of the story, do not include other content"
|
18 |
+
)
|
19 |
+
|
20 |
def text2story(text):
|
21 |
+
story_text = pipeline("text-generation", model="distilbert/distilgpt2",
|
22 |
+
max_length=200,
|
23 |
+
do_sample=True,
|
24 |
+
top_p=0.95,
|
25 |
+
temperature=0.7)
|
26 |
+
generation = story_text(story_prompt)
|
27 |
+
story_text = generation[0]['generated_text']
|
28 |
return story_text
|
29 |
|
30 |
# text2audio
|