Spaces:
Sleeping
Sleeping
import os | |
import gradio as gr | |
from langchain.llms import OpenAI | |
from langchain.prompts import PromptTemplate | |
from langchain.chains import LLMChain, SequentialChain | |
# Set your OpenAI API key (this will be set via HF Secrets, not hardcoded) | |
openai_api_key = os.getenv("OPENAI_API_KEY") | |
if not openai_api_key: | |
raise ValueError("Please set the OPENAI_API_KEY in your Hugging Face Space secrets.") | |
os.environ["OPENAI_API_KEY"] = openai_api_key | |
# Initialize LLM | |
llm = OpenAI(temperature=0.9) | |
# Prompt for restaurant name | |
prompt_template_name = PromptTemplate( | |
input_variables=["cuisine"], | |
template=""" | |
I want to start a premium restaurant serving {cuisine} cuisine. | |
Suggest a unique and classy name that reflects the richness and tradition of this food type. | |
Avoid clichés. The name should be memorable and ideal for a fine-dining experience. | |
""" | |
) | |
name_chain = LLMChain(llm=llm, prompt=prompt_template_name, output_key="restaraunt_name") | |
# Prompt for menu items | |
prompt_template_items = PromptTemplate( | |
input_variables=["restaraunt_name"], | |
template=""" | |
Create a detailed and elegant sample menu for a fine-dining restaurant named "{restaraunt_name}". | |
Structure the response into the following categories: | |
1. 🥗 Starters (3-4 items with names, short descriptions, and suggested prices) | |
2. 🍝 Main Course (3-4 items with names, short descriptions, and suggested prices) | |
3. 🍹 Drinks (3-4 items with names, short descriptions, and suggested prices) | |
Ensure that: | |
- Each item has a creative name and is culturally relevant. | |
- Prices are in USD and reflect a premium dining experience. | |
- The tone is refined, as if for a menu booklet or launch event. | |
""" | |
) | |
food_items_chain = LLMChain(llm=llm, prompt=prompt_template_items, output_key="menu_items") | |
# Combine chains | |
chain = SequentialChain( | |
chains=[name_chain, food_items_chain], | |
input_variables=["cuisine"], | |
output_variables=["restaraunt_name", "menu_items"], | |
verbose=True | |
) | |
# Gradio interface logic | |
def generate_restaurant(cuisine): | |
result = chain({"cuisine": cuisine}) | |
return result["restaraunt_name"], result["menu_items"] | |
# Gradio UI | |
with gr.Blocks() as demo: | |
gr.Markdown("## 🍽️ AI Restaurant Name & Gourmet Menu Generator") | |
cuisine_input = gr.Textbox(label="Enter Cuisine Type", placeholder="e.g., Korean, French, Lebanese") | |
name_output = gr.Textbox(label="✨ Suggested Restaurant Name") | |
menu_output = gr.Textbox(label="📜 Gourmet Menu", lines=15) | |
generate_button = gr.Button("Generate Menu") | |
generate_button.click(generate_restaurant, inputs=[cuisine_input], outputs=[name_output, menu_output]) | |
# Launch | |
demo.launch() | |