Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from langchain.llms import OpenAI
|
| 4 |
+
from langchain.prompts import PromptTemplate
|
| 5 |
+
from langchain.chains import LLMChain, SequentialChain
|
| 6 |
+
|
| 7 |
+
# Set your OpenAI API key (this will be set via HF Secrets, not hardcoded)
|
| 8 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 9 |
+
if not openai_api_key:
|
| 10 |
+
raise ValueError("Please set the OPENAI_API_KEY in your Hugging Face Space secrets.")
|
| 11 |
+
|
| 12 |
+
os.environ["OPENAI_API_KEY"] = openai_api_key
|
| 13 |
+
|
| 14 |
+
# Initialize LLM
|
| 15 |
+
llm = OpenAI(temperature=0.9)
|
| 16 |
+
|
| 17 |
+
# Prompt for restaurant name
|
| 18 |
+
prompt_template_name = PromptTemplate(
|
| 19 |
+
input_variables=["cuisine"],
|
| 20 |
+
template="""
|
| 21 |
+
I want to start a premium restaurant serving {cuisine} cuisine.
|
| 22 |
+
Suggest a unique and classy name that reflects the richness and tradition of this food type.
|
| 23 |
+
Avoid clichés. The name should be memorable and ideal for a fine-dining experience.
|
| 24 |
+
"""
|
| 25 |
+
)
|
| 26 |
+
name_chain = LLMChain(llm=llm, prompt=prompt_template_name, output_key="restaraunt_name")
|
| 27 |
+
|
| 28 |
+
# Prompt for menu items
|
| 29 |
+
prompt_template_items = PromptTemplate(
|
| 30 |
+
input_variables=["restaraunt_name"],
|
| 31 |
+
template="""
|
| 32 |
+
Create a detailed and elegant sample menu for a fine-dining restaurant named "{restaraunt_name}".
|
| 33 |
+
|
| 34 |
+
Structure the response into the following categories:
|
| 35 |
+
1. 🥗 Starters (3-4 items with names, short descriptions, and suggested prices)
|
| 36 |
+
2. 🍝 Main Course (3-4 items with names, short descriptions, and suggested prices)
|
| 37 |
+
3. 🍹 Drinks (3-4 items with names, short descriptions, and suggested prices)
|
| 38 |
+
|
| 39 |
+
Ensure that:
|
| 40 |
+
- Each item has a creative name and is culturally relevant.
|
| 41 |
+
- Prices are in USD and reflect a premium dining experience.
|
| 42 |
+
- The tone is refined, as if for a menu booklet or launch event.
|
| 43 |
+
"""
|
| 44 |
+
)
|
| 45 |
+
food_items_chain = LLMChain(llm=llm, prompt=prompt_template_items, output_key="menu_items")
|
| 46 |
+
|
| 47 |
+
# Combine chains
|
| 48 |
+
chain = SequentialChain(
|
| 49 |
+
chains=[name_chain, food_items_chain],
|
| 50 |
+
input_variables=["cuisine"],
|
| 51 |
+
output_variables=["restaraunt_name", "menu_items"],
|
| 52 |
+
verbose=True
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Gradio interface logic
|
| 56 |
+
def generate_restaurant(cuisine):
|
| 57 |
+
result = chain({"cuisine": cuisine})
|
| 58 |
+
return result["restaraunt_name"], result["menu_items"]
|
| 59 |
+
|
| 60 |
+
# Gradio UI
|
| 61 |
+
with gr.Blocks() as demo:
|
| 62 |
+
gr.Markdown("## 🍽️ AI Restaurant Name & Gourmet Menu Generator")
|
| 63 |
+
cuisine_input = gr.Textbox(label="Enter Cuisine Type", placeholder="e.g., Korean, French, Lebanese")
|
| 64 |
+
name_output = gr.Textbox(label="✨ Suggested Restaurant Name")
|
| 65 |
+
menu_output = gr.Textbox(label="📜 Gourmet Menu", lines=15)
|
| 66 |
+
|
| 67 |
+
generate_button = gr.Button("Generate Menu")
|
| 68 |
+
generate_button.click(generate_restaurant, inputs=[cuisine_input], outputs=[name_output, menu_output])
|
| 69 |
+
|
| 70 |
+
# Launch
|
| 71 |
+
demo.launch()
|