Geoffrey commited on
Commit
87aadd4
β€’
1 Parent(s): 158e328

application files

Browse files
Files changed (2) hide show
  1. app.py +40 -0
  2. helper.py +48 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+ import helper
4
+ import os
5
+
6
+ # Set your OpenAI API key
7
+ openai.api_key = os.getenv("API_KEY")
8
+
9
+
10
+
11
+ # Streamlit app title
12
+ st.title("Travel Planning πŸŒŽπŸš€πŸ–οΈ")
13
+
14
+ # User input textbox
15
+ user_input = st.text_input("Enter your destination :",placeholder='paris')
16
+
17
+ if st.button("Get Langchain Response"):
18
+
19
+ # Use OpenAI to enhance the response
20
+ # response = openai.Completion.create(
21
+ # engine="text-davinci-002",
22
+ # prompt=user_input,
23
+ # max_tokens=50
24
+ # )
25
+
26
+ response = helper.generate_restaurant_name_and_items(user_input)
27
+
28
+
29
+ st.subheader(f"Vacation Destination: {response['travel_place']}")
30
+ st.subheader(f"πŸ—ΊοΈ Places to visit: {response['places']}")
31
+
32
+ st.subheader('Must try 🍽️:')
33
+ menu_items = response['food'].strip()
34
+ menu_items_list = menu_items.split('\n\n')
35
+
36
+ for category in menu_items_list:
37
+ st.write(category)
38
+
39
+ st.subheader(f"Top πŸ”Ÿ things to do: {response['toDo']}")
40
+
helper.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.llms import OpenAI
2
+ from langchain.prompts import PromptTemplate
3
+ from langchain.chains import LLMChain
4
+ from langchain.chains import SequentialChain
5
+
6
+ import os
7
+ os.environ['OPENAI_API_KEY'] = os.getenv("API_KEY")
8
+
9
+ llm = OpenAI(temperature=0.7)
10
+
11
+ def generate_restaurant_name_and_items(travel_place):
12
+ # Chain 1: Restaurant Name
13
+ prompt_template_name = PromptTemplate(
14
+ input_variables=['travel_place'],
15
+ template="I want to travel to {travel_place}. Suggest some places to visi with relevant emoji's for each places and description"
16
+ )
17
+
18
+ name_chain = LLMChain(llm=llm, prompt=prompt_template_name, output_key="places")
19
+
20
+ # Chain 2: Menu Items
21
+ prompt_template_items = PromptTemplate(
22
+ input_variables=['travel_place'],
23
+ template="""Suggest some must try food items at {travel_place}. Return it as a comma separate items with relevant emoji's for food items"""
24
+ )
25
+
26
+ food_items_chain = LLMChain(llm=llm, prompt=prompt_template_items, output_key="food")
27
+
28
+ # Chain 3: Things to do
29
+ prompt_template_toDo = PromptTemplate(
30
+ input_variables=['travel_place'],
31
+ template="""Suggest Top 10 things to do in {travel_place}. Return with estimated cost and with relevant emoji's for each."""
32
+ )
33
+
34
+ todo_items_chain = LLMChain(llm=llm, prompt=prompt_template_toDo, output_key="toDo")
35
+
36
+ chain = SequentialChain(
37
+ chains=[name_chain, food_items_chain, todo_items_chain],
38
+ input_variables=['travel_place'],
39
+ output_variables=['places', 'food', 'toDo']
40
+ )
41
+
42
+ response = chain({'travel_place': travel_place})
43
+
44
+
45
+ return response
46
+
47
+ if __name__ == "__main__":
48
+ print(generate_restaurant_name_and_items("Italian"))