Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,59 +1,43 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import os
|
|
|
|
| 3 |
from langchain.chains import LLMChain, SequentialChain
|
| 4 |
-
from langchain.prompts import PromptTemplate
|
| 5 |
from langchain.llms import OpenAI
|
| 6 |
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
openai = os.getenv("openai")
|
| 12 |
-
if not openai:
|
| 13 |
-
raise ValueError("Please set the in your Hugging space")
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
llm = OpenAI(temperature=0.9)
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
input_variables=[
|
| 23 |
-
|
| 24 |
)
|
| 25 |
-
name_chain = LLMChain(llm=llm, prompt=prompt_template_name, output_key="restaurant_name")
|
| 26 |
-
|
| 27 |
-
# Chain 2: Menu items with sections
|
| 28 |
-
prompt_template_items = PromptTemplate(
|
| 29 |
-
input_variables=["restaurant_name"],
|
| 30 |
-
template=(
|
| 31 |
-
"Create a detailed menu for a restaurant named '{restaurant_name}'. "
|
| 32 |
-
"The menu should include unique and appealing dishes under the following sections:\n"
|
| 33 |
-
"1. Breakfast\n"
|
| 34 |
-
"2. Lunch\n"
|
| 35 |
-
"3. Dinner\n"
|
| 36 |
-
"Each section should have at least 3 items with short descriptions. The menu should reflect the theme and cuisine of the restaurant."
|
| 37 |
-
)
|
| 38 |
-
)
|
| 39 |
-
food_items_chain = LLMChain(llm=llm, prompt=prompt_template_items, output_key="menu_items")
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
def generate_restaurant_idea(cuisine):
|
| 50 |
-
result = chain({'cuisine': cuisine})
|
| 51 |
-
return f"🍽️ **Restaurant Name:** {result['restaurant_name']}\n\n📜 **Menu:**\n{result['menu_items']}"
|
| 52 |
-
|
| 53 |
-
gr.Interface(
|
| 54 |
-
fn=generate_restaurant_idea,
|
| 55 |
-
inputs=gr.Textbox(lines=1, placeholder="Enter a cuisine type, e.g., Italian, Japanese, etc."),
|
| 56 |
-
outputs=gr.Markdown(),
|
| 57 |
-
title="🍴 Restaurant Business Idea Generator",
|
| 58 |
-
description="Enter a cuisine type and get a fancy restaurant name along with a structured menu for breakfast, lunch, and dinner."
|
| 59 |
-
).launch()
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
from langchain.chains import LLMChain, SequentialChain
|
| 4 |
+
from langchain.prompts import PromptTemplate
|
| 5 |
from langchain.llms import OpenAI
|
| 6 |
|
| 7 |
+
os.environ["OPENAI_API_KEY"]= os.getenv["OPENAI_API_KEY"]
|
| 8 |
+
llm = OpenAI(temperature= 0.5)
|
| 9 |
|
| 10 |
+
prompt_name = PromptTemplate(
|
| 11 |
+
input_variables= ['cuisine'],
|
| 12 |
+
template = "I want to open a chic restuarant for {cuisine} food. Suggest an eye-catching fancy name for this"
|
| 13 |
+
)
|
| 14 |
|
| 15 |
+
name_chain = LLMChain(llm=llm, prompt =prompt_name, output_key = "restaurant_name" )
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
promp_items= PromptTemplate(
|
| 18 |
+
input_variables=['restaurant_name'],
|
| 19 |
+
template = ["Create a menu for {restaurant_name}. Divide it into sections like starters, brekfast, lunch and dinner finishing it off with desserts. "
|
| 20 |
+
"a small description underneath each dish. price across. The format of a five michelin star restaurant."]
|
| 21 |
+
)
|
| 22 |
|
| 23 |
+
menu_chain = LLMChain(llm=llm, prompt= promp_items, output_key = "men_items")
|
|
|
|
| 24 |
|
| 25 |
+
main_chain = SequentialChain(
|
| 26 |
+
chains= [name_chain, menu_chain],
|
| 27 |
+
input_variables = ['cuisine'],
|
| 28 |
+
output_variables = ['restaurant_name', 'men_items']
|
| 29 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
def hotel_function(cuisine):
|
| 32 |
+
result = main_chain({'cuisine': cuisine} )
|
| 33 |
+
return result['restaurant_name'], result['menu_items']
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
iface = gr.Interface(
|
| 37 |
+
fn = hotel_function,
|
| 38 |
+
inputs = gr.Textbox(label = "Enter cuisine:") ,
|
| 39 |
+
output = [gr.TextBox(label= "Restaurant_name"), gr.TextBox(label = "Menu Items")],
|
| 40 |
+
title = "Restaurant Menu and Items",
|
| 41 |
+
description="Powered by Langchain and OpenAI")
|
| 42 |
|
| 43 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|