Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from prompt_generator import generate_prompt
|
| 3 |
from image_generator import generate_image
|
|
|
|
| 4 |
|
| 5 |
-
def generate_artwork(description, style, enhance_details):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# 生成提示词
|
| 7 |
prompt = generate_prompt(description)
|
| 8 |
|
| 9 |
# 如果选中了增强细节的选项,修改提示
|
| 10 |
if enhance_details:
|
| 11 |
-
prompt += "
|
| 12 |
|
| 13 |
# 根据用户选择的风格修改提示
|
| 14 |
-
if style == "
|
| 15 |
-
prompt += "
|
| 16 |
-
elif style == "
|
| 17 |
-
prompt += "赛博朋克"
|
| 18 |
else:
|
| 19 |
prompt += "写实风格"
|
| 20 |
|
|
@@ -25,17 +30,19 @@ def generate_artwork(description, style, enhance_details):
|
|
| 25 |
# 创建 Gradio 界面
|
| 26 |
with gr.Blocks() as demo:
|
| 27 |
with gr.Row():
|
| 28 |
-
description_input = gr.Textbox(label="输入描述", placeholder="
|
| 29 |
-
style_selector = gr.Dropdown(choices=["
|
| 30 |
detail_checkbox = gr.Checkbox(label="增强细节")
|
|
|
|
| 31 |
|
| 32 |
with gr.Row():
|
| 33 |
-
output_prompt = gr.Textbox(label="生成提示", interactive=False)
|
| 34 |
-
output_image = gr.Image(label="生成图像", interactive=False)
|
| 35 |
|
| 36 |
generate_button = gr.Button("生成作品")
|
| 37 |
generate_button.click(generate_artwork,
|
| 38 |
-
inputs=[description_input, style_selector, detail_checkbox],
|
| 39 |
outputs=[output_prompt, output_image])
|
| 40 |
|
| 41 |
demo.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from prompt_generator import generate_prompt
|
| 3 |
from image_generator import generate_image
|
| 4 |
+
from whisper_model import transcribe_audio
|
| 5 |
|
| 6 |
+
def generate_artwork(description, style, enhance_details, audio_file):
|
| 7 |
+
# 如果上传了音频文件,进行语音转文本
|
| 8 |
+
if audio_file is not None:
|
| 9 |
+
description = transcribe_audio(audio_file)
|
| 10 |
+
|
| 11 |
# 生成提示词
|
| 12 |
prompt = generate_prompt(description)
|
| 13 |
|
| 14 |
# 如果选中了增强细节的选项,修改提示
|
| 15 |
if enhance_details:
|
| 16 |
+
prompt += "有增强细节
|
| 17 |
|
| 18 |
# 根据用户选择的风格修改提示
|
| 19 |
+
if style == "奇幻":
|
| 20 |
+
prompt += " 奇幻风格"
|
| 21 |
+
elif style == "赛博朋克":
|
| 22 |
+
prompt += "赛博朋克风格"
|
| 23 |
else:
|
| 24 |
prompt += "写实风格"
|
| 25 |
|
|
|
|
| 30 |
# 创建 Gradio 界面
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
with gr.Row():
|
| 33 |
+
description_input = gr.Textbox(label="请输入描述", placeholder="例如:天空中的魔法树屋")
|
| 34 |
+
style_selector = gr.Dropdown(choices=["奇幻", "赛博朋克", "现实主义"], label="选择风格")
|
| 35 |
detail_checkbox = gr.Checkbox(label="增强细节")
|
| 36 |
+
audio_input = gr.Audio(source="microphone", label="录制您的描述", type="filepath")
|
| 37 |
|
| 38 |
with gr.Row():
|
| 39 |
+
output_prompt = gr.Textbox(label="生成的提示词", interactive=False)
|
| 40 |
+
output_image = gr.Image(label="生成的图像", interactive=False)
|
| 41 |
|
| 42 |
generate_button = gr.Button("生成作品")
|
| 43 |
generate_button.click(generate_artwork,
|
| 44 |
+
inputs=[description_input, style_selector, detail_checkbox, audio_input],
|
| 45 |
outputs=[output_prompt, output_image])
|
| 46 |
|
| 47 |
demo.launch()
|
| 48 |
+
|