|
@@ -7,12 +7,14 @@ import gradio as gr
|
|
|
def mock_img(text: str):
|
|
|
return [
|
|
|
{
|
|
|
- "caption": "科学家们使用克隆技术",
|
|
|
- "url": "https://image.limaogushi.com/file/picture-books/image/f2/d8/7ae32095-6e8c-4328-a218-6fe57e49bbc2.jpg",
|
|
|
+ "caption": "植物克隆过程示意图",
|
|
|
+ "url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/85/20240710/1b61f1c0/5a69fb02-051b-4708-9a19-83b8f1f5fce2-1.png?Expires=1720710640&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=lk4qpxmXBYPzWl%2FHdfpg4RnSgSU%3D",
|
|
|
+ "description": "图中展示了一棵植物和从植物上剪下的一小段枝条,该枝条被插入土壤中。过一段时间,这小段 枝条生根发芽,长成了一棵新的、和原植物一模一样的新植物。",
|
|
|
},
|
|
|
{
|
|
|
- "caption": "克隆羊多利的诞生",
|
|
|
- "url": "https://image.limaogushi.com/file/picture-books/image/97/98/75cf0a7b-cb27-44b3-beae-7ab24488ff8c.jpg",
|
|
|
+ "caption": "克隆羊多利的照片",
|
|
|
+ "url": " https://dashscope-result-hz.oss-cn-hangzhou.aliyuncs.com/1d/63/20240710/522176a8/0572556b-f855-4fd4-bd02-aea8a72d7fd1-1.png?Expires=1720710681&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=RT21mWAWpFTwRA5LU20GomgBxuk%3D",
|
|
|
+ "description": " 图中展示了克隆羊多利站在草地上,她看起来非常健康,和普通的羊没有区别。背景是实验室的轮廓 ,暗示了她的诞生地。",
|
|
|
},
|
|
|
]
|
|
|
|
|
@@ -31,14 +33,26 @@ def mock_story(query: str):
|
|
|
|
|
|
from kg import story_to_imgs
|
|
|
|
|
|
+story_existed = False
|
|
|
+
|
|
|
|
|
|
def generate_image(story):
|
|
|
|
|
|
- res = story_to_imgs(story)
|
|
|
+
|
|
|
+ res = mock_img(story)
|
|
|
md = ""
|
|
|
|
|
|
for i in range(len(res)):
|
|
|
- md += f"{res[i]['caption']}\n![{res[i]['caption']}]({res[i]['url']})\n\n"
|
|
|
+ md += f"## {res[i]['caption']}\n\n"
|
|
|
+ md += f"{res[i]['description']} \n "
|
|
|
+ md += f"<img src=\"{res[i]['url']}\" width = \"500\" div align=center />\n"
|
|
|
+ if i != len(res) - 1:
|
|
|
+ md += "\n\n"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ with open("生成的绘本.md", "w", encoding="utf-8") as f:
|
|
|
+ f.write(md)
|
|
|
return md
|
|
|
|
|
|
|
|
@@ -46,28 +60,29 @@ from answerQuestions import generateStory
|
|
|
|
|
|
|
|
|
def generate_story(query):
|
|
|
-
|
|
|
+ story_existed = True
|
|
|
+ return mock_story(query)
|
|
|
return generateStory(query)
|
|
|
|
|
|
|
|
|
-
|
|
|
with gr.Blocks() as demo:
|
|
|
gr.Markdown("# 绘本生成器")
|
|
|
|
|
|
- with gr.Row():
|
|
|
- with gr.Column():
|
|
|
+ with gr.Column():
|
|
|
+ with gr.Row():
|
|
|
input_text = gr.Textbox(label="输入")
|
|
|
- with gr.Row():
|
|
|
- clear_btn = gr.Button("清空")
|
|
|
- story_btn = gr.Button("生成故事", variant="primary")
|
|
|
- with gr.Row():
|
|
|
- img_btn = gr.Button("生成绘本", variant="primary")
|
|
|
- with gr.Column():
|
|
|
- story_output = gr.Textbox(label="生成的故事", interactive=False, lines=10)
|
|
|
+ with gr.Row():
|
|
|
+ clear_btn = gr.Button("清空")
|
|
|
+ story_btn = gr.Button("生成故事", variant="primary")
|
|
|
+ img_btn = gr.Button(
|
|
|
+ "生成绘本", variant="primary", interactive=story_existed
|
|
|
+ )
|
|
|
+ with gr.Row():
|
|
|
+ story_output = gr.Textbox(label="故事", interactive=False)
|
|
|
story_btn.click(generate_story, inputs=input_text, outputs=story_output)
|
|
|
- with gr.Column():
|
|
|
- gr.Markdown("## 生成的绘本")
|
|
|
- img_output = gr.Markdown(label="生成的绘本")
|
|
|
+
|
|
|
+
|
|
|
+ img_output = gr.Markdown(label="绘本")
|
|
|
img_btn.click(generate_image, inputs=story_output, outputs=img_output)
|
|
|
|
|
|
clear_btn.click(
|