|
|
import gradio as gr |
|
|
import random |
|
|
|
|
|
|
|
|
|
|
|
dinner_options = { |
|
|
"紅燒牛肉麵": "https://images.unsplash.com/photo-1563823439066-88b901614f04?ixlib=rb-4.0.3&q=85&fm=jpg&crop=entropy&cs=srgb", |
|
|
"蒜香奶油蝦義大利麵": "https://images.unsplash.com/photo-1627878347895-df5698b67272?ixlib=rb-4.0.3&q=85&fm=jpg&crop=entropy&cs=srgb", |
|
|
"日式豬排咖哩飯": "https://images.unsplash.com/photo-1548694086-63d08f5d0232?ixlib=rb-4.0.3&q=85&fm=jpg&crop=entropy&cs=srgb", |
|
|
"麻婆豆腐": "https://images.unsplash.com/photo-1596796530661-d7072a394879?ixlib=rb-4.0.3&q=85&fm=jpg&crop=entropy&cs=srgb", |
|
|
"三杯雞": "https://images.unsplash.com/photo-1563823439066-88b901614f04?ixlib=rb-4.0.3&q=85&fm=jpg&crop=entropy&cs=srgb", |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
def pick_dinner(): |
|
|
|
|
|
dish, image_url = random.choice(list(dinner_options.items())) |
|
|
return f"今晚吃 **{dish}**!", image_url |
|
|
|
|
|
|
|
|
with gr.Blocks(theme=gr.themes.Soft()) as demo: |
|
|
gr.Markdown("# 🍜 晚餐挑選器") |
|
|
gr.Markdown("選擇困難?交給我來決定你今晚要吃什麼!") |
|
|
|
|
|
with gr.Row(): |
|
|
with gr.Column(scale=1): |
|
|
|
|
|
btn = gr.Button("隨機挑選") |
|
|
|
|
|
with gr.Column(scale=2): |
|
|
|
|
|
output_text = gr.Markdown() |
|
|
|
|
|
output_image = gr.Image(label="圖片參考", interactive=False) |
|
|
|
|
|
|
|
|
btn.click( |
|
|
fn=pick_dinner, |
|
|
outputs=[output_text, output_image] |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |