Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ os.system("pip install transformers==4.36.2")
|
|
7 |
|
8 |
# 加載 Hugging Face 的模型
|
9 |
image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
10 |
-
story_generator = pipeline("text-generation", model="facebook/opt-1
|
11 |
|
12 |
# 圖片 → 文字(生成描述)
|
13 |
def img2text(image_path):
|
@@ -17,7 +17,7 @@ def img2text(image_path):
|
|
17 |
# 文字 → 故事(生成完整故事)
|
18 |
def text2story(text):
|
19 |
prompt = f"Write a fun and magical children's story based on this idea: {text}.\n\nOnce upon a time..."
|
20 |
-
story = story_generator(prompt, max_length=
|
21 |
return story
|
22 |
|
23 |
# 故事 → 語音(TTS)
|
|
|
7 |
|
8 |
# 加載 Hugging Face 的模型
|
9 |
image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
10 |
+
story_generator = pipeline("text-generation", model="facebook/opt-350m", device=-1)
|
11 |
|
12 |
# 圖片 → 文字(生成描述)
|
13 |
def img2text(image_path):
|
|
|
17 |
# 文字 → 故事(生成完整故事)
|
18 |
def text2story(text):
|
19 |
prompt = f"Write a fun and magical children's story based on this idea: {text}.\n\nOnce upon a time..."
|
20 |
+
story = story_generator(prompt, max_length=150, do_sample=True, temperature=0.8, top_p=0.9, repetition_penalty=1.2)[0]['generated_text']
|
21 |
return story
|
22 |
|
23 |
# 故事 → 語音(TTS)
|