Xakiy commited on
Commit
162596b
·
verified ·
1 Parent(s): 645bcd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -47
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
- llm = OpenAI(temperature=0.9, openai_api_key=os.getenv("openai"))
 
 
 
9
 
10
- # Set OpenAI API key
11
- openai = os.getenv("openai")
12
- if not openai:
13
- raise ValueError("Please set the in your Hugging space")
14
 
15
- os.environ["openai"] = openai
 
 
 
 
16
 
17
- # Define the LLM
18
- llm = OpenAI(temperature=0.9)
19
 
20
- # Chain 1: Fancy restaurant name
21
- prompt_template_name = PromptTemplate(
22
- input_variables=["cuisine"],
23
- template="I want to open a fancy restaurant for {cuisine} cuisine. Suggest a creative and appealing name for this restaurant."
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
- # Combine chains
42
- chain = SequentialChain(
43
- chains=[name_chain, food_items_chain],
44
- input_variables=["cuisine"],
45
- output_variables=["restaurant_name", "menu_items"]
46
- )
 
 
 
 
 
47
 
48
- # Gradio interface
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()