Chong-U Lim commited on
Commit
1ac2cc0
β€’
1 Parent(s): a0ecfdf
Files changed (2) hide show
  1. main.py β†’ app.py +3 -9
  2. langchain_helper.py +44 -0
main.py β†’ app.py RENAMED
@@ -1,11 +1,5 @@
1
  import gradio as gr
2
-
3
-
4
- def generate_restaurant_name_and_items(cuisine: str) -> dict[str, str]:
5
- return {
6
- "restaurant_name": "Curry Delight",
7
- "menu_items": "Butter Chicken, Naan, Paneer Tikka, Chole Bhature, Lassi, Gulab Jamun",
8
- }
9
 
10
 
11
  def update_outputs(cuisine: str) -> tuple[str, str]:
@@ -20,7 +14,7 @@ def update_outputs(cuisine: str) -> tuple[str, str]:
20
  return f"## {restaurant_name}", menu_items_formatted
21
 
22
 
23
- with gr.Blocks() as app:
24
  gr.Markdown("# Restaurant Name Generator")
25
  inp_cuisine = gr.Dropdown(
26
  ["Indian", "Italian", "Mexican", "Arabic"],
@@ -38,4 +32,4 @@ with gr.Blocks() as app:
38
 
39
 
40
  if __name__ == "__main__":
41
- app.launch()
 
1
  import gradio as gr
2
+ from langchain_helper import generate_restaurant_name_and_items
 
 
 
 
 
 
3
 
4
 
5
  def update_outputs(cuisine: str) -> tuple[str, str]:
 
14
  return f"## {restaurant_name}", menu_items_formatted
15
 
16
 
17
+ with gr.Blocks() as gradio_app:
18
  gr.Markdown("# Restaurant Name Generator")
19
  inp_cuisine = gr.Dropdown(
20
  ["Indian", "Italian", "Mexican", "Arabic"],
 
32
 
33
 
34
  if __name__ == "__main__":
35
+ gradio_app.launch()
langchain_helper.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from keys import openapi_key
3
+ from langchain.llms import OpenAI
4
+ from langchain.prompts import PromptTemplate
5
+ from langchain.chains import LLMChain, SequentialChain
6
+
7
+ os.environ["OPENAI_API_KEY"] = openapi_key
8
+ llm = OpenAI(temperature=0.7)
9
+
10
+ prompt_template_name = PromptTemplate(
11
+ input_variables=["cuisine"],
12
+ template="I want to open a restaurant for {cuisine} food. Suggest a fancy name for this.",
13
+ )
14
+
15
+ name_chain = LLMChain(
16
+ llm=llm, prompt=prompt_template_name, output_key="restaurant_name"
17
+ )
18
+
19
+ prompt_template_items = PromptTemplate(
20
+ input_variables=["restaurant_name"],
21
+ template="Suggest some menu items for {restaurant_name}. Return it as a comma separated string.",
22
+ )
23
+
24
+ food_items_chain = LLMChain(
25
+ llm=llm, prompt=prompt_template_items, output_key="menu_items"
26
+ )
27
+
28
+ chain = SequentialChain(
29
+ chains=[name_chain, food_items_chain],
30
+ input_variables=["cuisine"],
31
+ output_variables=["restaurant_name", "menu_items"],
32
+ )
33
+
34
+
35
+ def generate_restaurant_name_and_items(cuisine: str) -> dict[str, str]:
36
+ return chain({"cuisine": cuisine})
37
+ # return {
38
+ # "restaurant_name": "Curry Delight",
39
+ # "menu_items": "Butter Chicken, Naan, Paneer Tikka, Chole Bhature, Lassi, Gulab Jamun",
40
+ # }
41
+
42
+
43
+ if __name__ == "__main__":
44
+ print(generate_restaurant_name_and_items("Singaporean"))