Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,9 +10,13 @@ def img2text(url):
|
|
10 |
def text2story(text):
|
11 |
story_generator = pipeline("text-generation", model="pranavpsv/gpt2-genre-story-generator", device_map="auto", return_full_text=False)
|
12 |
prompt = f"<BOS> {text}"
|
13 |
-
generated = story_generator(prompt, max_new_tokens=
|
14 |
story_text = generated[0]['generated_text']
|
15 |
|
|
|
|
|
|
|
|
|
16 |
# Split into sentences
|
17 |
sentences = re.split(r'(?<=[.!?])\s+', story_text.strip())
|
18 |
|
@@ -39,7 +43,7 @@ def text2story(text):
|
|
39 |
return final_story
|
40 |
|
41 |
def text2audio(story_text):
|
42 |
-
audio_generator = pipeline("text-to-speech", model="
|
43 |
audio_output = audio_generator(story_text)
|
44 |
return audio_output
|
45 |
|
|
|
10 |
def text2story(text):
|
11 |
story_generator = pipeline("text-generation", model="pranavpsv/gpt2-genre-story-generator", device_map="auto", return_full_text=False)
|
12 |
prompt = f"<BOS> {text}"
|
13 |
+
generated = story_generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)
|
14 |
story_text = generated[0]['generated_text']
|
15 |
|
16 |
+
# Remove leading ". " if present
|
17 |
+
if story_text.startswith(". "):
|
18 |
+
story_text = story_text[2:]
|
19 |
+
|
20 |
# Split into sentences
|
21 |
sentences = re.split(r'(?<=[.!?])\s+', story_text.strip())
|
22 |
|
|
|
43 |
return final_story
|
44 |
|
45 |
def text2audio(story_text):
|
46 |
+
audio_generator = pipeline("text-to-speech", model="khof312/mms-tts-swh-female-1")
|
47 |
audio_output = audio_generator(story_text)
|
48 |
return audio_output
|
49 |
|