File size: 7,347 Bytes
2501d7c
baceaba
2501d7c
 
baceaba
2501d7c
baceaba
2501d7c
 
 
 
 
 
baceaba
2501d7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import os
import gradio as gr
from langchain.chains import LLMChain, SequentialChain
from langchain.prompts import PromptTemplate
from langchain_community.llms import OpenAI  # <-- UPDATED IMPORT

# Get OpenAI API key from environment variable
openai_api_key = os.getenv("OPENAI_API_KEY")
llm = OpenAI(openai_api_key=openai_api_key, temperature=0.9)

# Define prompt templates
prompt_template_name = PromptTemplate(
    input_variables=['cuisine'],
    template="I want to open a restaurant for {cuisine} food. Suggest a fancy name for this"
)
name_chain = LLMChain(llm=llm, prompt=prompt_template_name, output_key="restaraunt_name")

prompt_template_items = PromptTemplate(
    input_variables=['restaraunt_name', 'cuisine'],
    template="Suggest a comprehensive menu for {restaraunt_name} which is {cuisine} cuisine. For each item, provide a brief, one-sentence description. Do not use any numbering or bullet points. Only mention items names and descriptions, break down according to category. Format the output as 'Category:\nItem Name - Description\n...'"
)
food_items_chain = LLMChain(llm=llm, prompt=prompt_template_items, output_key="menu_items")

chain = SequentialChain(
    chains=[name_chain, food_items_chain],
    input_variables=['cuisine'],
    output_variables=['restaraunt_name', 'menu_items']
)

TOP_CUISINES = [
    "Italian", "Chinese", "Japanese", "Mexican", "Indian",
    "French", "Thai", "Mediterranean", "American", "Spanish"
]

def generate_restaurant(cuisine):
    outputs = chain({'cuisine': cuisine})
    restaurant_name = outputs['restaraunt_name']
    menu_items_str = outputs['menu_items']

    lines = menu_items_str.strip().split('\n')
    menu_html = """
    <style>
        .menu-container {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 16px;
            padding: 16px;
            background-color: #f0e6d2;
            border-radius: 12px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .menu-tile {
            background-color: #fffaf0;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
            padding: 16px;
            text-align: center;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            border: 1px solid #d2b48c;
        }
        .menu-tile h4 {
            margin: 0 0 8px 0;
            font-weight: bold;
            color: #5c4033;
            font-family: 'Comic Neue', cursive, sans-serif;
        }
        .menu-description {
            margin: 0;
            color: #8b4513;
            font-size: 0.9em;
            line-height: 1.4;
            text-align: left;
            font-family: 'Comic Neue', cursive, sans-serif;
        }
        .category-header {
            grid-column: 1 / -1;
            font-size: 1.5em;
            font-weight: bold;
            color: #a0522d;
            margin-top: 20px;
            margin-bottom: 10px;
            text-align: left;
            font-family: 'Comic Neue', cursive, sans-serif;
        }
    </style>
    <div class="menu-container">
    """
    current_category = ""
    for line in lines:
        line = line.strip()
        if not line:
            continue
        if ":" in line:
            current_category = line.replace(":", "")
            menu_html += f'<div class="category-header">{current_category}</div>'
        else:
            parts = line.split(' - ', 1)
            if len(parts) == 2:
                item_name, item_description = parts
                menu_html += f"""
                <div class="menu-tile">
                    <h4>{item_name.strip()}</h4>
                    <p class="menu-description">{item_description.strip()}</p>
                </div>
                """
    menu_html += "</div>"
    return restaurant_name, menu_html

def on_generate(selected, custom):
    cuisine = custom.strip() if custom and custom.strip() else selected
    return generate_restaurant(cuisine)

with gr.Blocks(title="Restaurant Business Generator", theme="soft", css="""
    @import url('https://fonts.googleapis.com/css2?family=Comic+Neue:wght@400;700&display=swap');
    body {
        font-family: 'Comic Neue', 'Comic Sans MS', cursive, sans-serif;
    }
    .gradio-container {
        background-color: #f5f5dc;
        color: #5c4033;
    }
    .gradio-container h1, .gradio-container h2, .gradio-container h3, .gradio-container h4, .gradio-container h5, .gradio-container h6 {
        color: #5c4033;
    }
    .gradio-container label {
        color: #8b4513 !important;
        font-family: 'Comic Neue', cursive, sans-serif;
    }
    .gradio-container .gr-markdown p {
        color: #8b4513 !important;
    }
    .gradio-container input[type="text"], .gradio-container textarea {
        border-color: #d2b48c;
    }
    .gradio-container .gr-dropdown {
        border-color: #d2b48c;
    }
    .gradio-container .gr-dropdown-selected {
        background-color: #fffaf0;
    }
    #generate-btn {
        background-color: #a0522d;
        color: white;
        font-weight: bold;
        border: none;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
    #generate-btn:hover {
        background-color: #8b4513;
    }
    .output-class {
        background-color: #faebd7;
        border: 1px solid #d2b48c;
        border-radius: 8px;
        padding: 10px;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
    }
    #restaurant-name-output textarea {
        color: #5c4033;
        font-weight: bold;
        font-size: 1.1em;
        background-color: #fffaf0 !important;
        border: 1px solid #d2b48c !important;
    }
    :root {
        --primary-50: #fffaf0 !important;
        --primary-100: #fff5e1 !important;
        --primary-200: #fff0d2 !important;
        --primary-300: #ffe9b9 !important;
        --primary-400: #ffe1a0 !important;
        --primary-500: #a0522d !important;
        --primary-600: #8b4513 !important;
        --primary-700: #5c4033 !important;
        --primary-800: #4a332a !important;
        --primary-900: #3b2820 !important;
        --primary-950: #291a14 !important;
    }
""") as demo:
    gr.Markdown("<h1 style='text-align:center; color: #5c4033;'>✨ The Magical Restaurant Idea Generator ✨</h1>")
    with gr.Row():
        with gr.Column(scale=1, min_width=200):
            gr.Markdown("<p style='color:#8b4513; text-align:center;'>Choose a cuisine or type your own, and let the magic happen! We'll give you a cute restaurant name and a delightful menu.</p>")
            cuisine_dropdown = gr.Dropdown(choices=TOP_CUISINES, label="Popular Cuisines", value=TOP_CUISINES[0])
            cuisine_textbox = gr.Textbox(label="Or enter a custom cuisine", placeholder="e.g. Vietnamese, Peruvian")
            generate_btn = gr.Button("Create My Restaurant! 🪄", variant="primary", elem_id="generate-btn")
        with gr.Column(scale=2, elem_classes="output-class"):
            name_output = gr.Textbox(label="Suggested Restaurant Name", interactive=False, elem_id="restaurant-name-output")
            menu_output = gr.HTML(label="Suggested Menu Items")

    generate_btn.click(fn=on_generate, inputs=[cuisine_dropdown, cuisine_textbox], outputs=[name_output, menu_output])

if __name__ == "__main__":
    demo.launch()