import gradio as gr
import random
subjects = ['You', 'Your family', 'Your friends', 'A stranger', 'An opportunity']
verbs = ['will find', 'may encounter', 'should seek', 'will discover', 'might stumble upon']
objects = ['happiness', 'success', 'a challenge', 'love', 'wisdom']
timeframes = ['soon', 'in the near future', 'when you least expect it', 'after overcoming an obstacle', 'as a result of your hard work']
def generate_fortune(name):
fortune = f"{random.choice(subjects)} {random.choice(verbs)} {random.choice(objects)} {random.choice(timeframes)}."
if name:
return f"{name}, {fortune.lower()}"
return fortune
def fortune_cookie(name):
return generate_fortune(name)
with gr.Blocks(title="Fortune Cookie Generator") as demo:
gr.Markdown("# 🥠Fortune Cookie Generator")
gr.Markdown("Get your personalized fortune!")
with gr.Row():
name_input = gr.Textbox(label="Enter your name (optional)")
fortune_output = gr.Textbox(label="Your Fortune")
generate_button = gr.Button("Get Fortune")
generate_button.click(
fn=fortune_cookie,
inputs=name_input,
outputs=fortune_output
)
demo.launch()