|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script> |
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" /> |
|
<style> |
|
body { font-family: Arial, sans-serif; background-color: #f7f1e3; } |
|
</style> |
|
</head> |
|
<body> |
|
<gradio-lite> |
|
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() |
|
</gradio-lite> |
|
</body> |
|
</html> |