Spaces:
Sleeping
Sleeping
palitrajarshi
commited on
Commit
·
becbcc8
1
Parent(s):
a53486f
Upload 2 files
Browse files- travel.png +0 -0
- utils3.py +57 -0
travel.png
ADDED
utils3.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.llms import OpenAI
|
2 |
+
from langchain.prompts import PromptTemplate
|
3 |
+
from langchain.chains import LLMChain
|
4 |
+
from langchain.tools import DuckDuckGoSearchRun
|
5 |
+
|
6 |
+
# Function to generate video script
|
7 |
+
def generate_script(prompt,duration,origin,budget,api_key):
|
8 |
+
|
9 |
+
# Template for generating 'Itinerary' using search engine
|
10 |
+
itinerary_template = PromptTemplate(
|
11 |
+
input_variables = ['location','duration','DuckDuckGo_Search','expense','origin'],
|
12 |
+
template='Please come up with a detailed itinerary for a trip to {location} for a duration: {duration} days using this search data {DuckDuckGo_Search}. The maximum budget per person in INR is {expense}. The origin of the journey is {origin}. '
|
13 |
+
)
|
14 |
+
|
15 |
+
# Template for generating 'Conveyance Used' using search engine
|
16 |
+
conveyance_template = PromptTemplate(
|
17 |
+
input_variables = ['location', 'origin', 'DuckDuckGo_Search'],
|
18 |
+
#template='Based on this itinerary: {itinerary}, please mention the conveyance to be taken during the trip while going from one place to another using this search data {DuckDuckGo_Search} '
|
19 |
+
template='Please mention the different ways to reach the {location} from {origin} and the different modes of travel using this search data {DuckDuckGo_Search} '
|
20 |
+
)
|
21 |
+
|
22 |
+
# Template for generating 'Cuisines' using search engine
|
23 |
+
cuisines_template = PromptTemplate(
|
24 |
+
input_variables = ['itinerary', 'DuckDuckGo_Search'],
|
25 |
+
template='Based on this itinerary: {itinerary}, please mention the cuisines that I can try during the trip using this search data {DuckDuckGo_Search} '
|
26 |
+
)
|
27 |
+
|
28 |
+
# Template for generating 'Accomodation' using search engine
|
29 |
+
accomodation_template = PromptTemplate(
|
30 |
+
input_variables = ['itinerary', 'DuckDuckGo_Search'],
|
31 |
+
template='Based on this itinerary: {itinerary}, please mention the accomodation/hotel that I can stay in during the trip using this search data {DuckDuckGo_Search} '
|
32 |
+
)
|
33 |
+
|
34 |
+
#Setting up OpenAI LLM
|
35 |
+
llm = OpenAI(temperature=0.5, openai_api_key=api_key, model_name='gpt-3.5-turbo')
|
36 |
+
|
37 |
+
#Creating chain for 'Itinerary', 'Conveyance', 'Cuisines', 'Accomodation'
|
38 |
+
itinerary_chain = LLMChain(llm=llm, prompt=itinerary_template, verbose=True)
|
39 |
+
conveyance_chain = LLMChain(llm=llm, prompt=conveyance_template, verbose=True)
|
40 |
+
cuisines_chain = LLMChain(llm=llm, prompt=cuisines_template, verbose=True)
|
41 |
+
accomodation_chain = LLMChain(llm=llm, prompt=accomodation_template, verbose=True)
|
42 |
+
|
43 |
+
|
44 |
+
# https://python.langchain.com/docs/modules/agents/tools/integrations/ddg
|
45 |
+
search = DuckDuckGoSearchRun()
|
46 |
+
search_result = search.run(prompt)
|
47 |
+
|
48 |
+
# Executing the chains we created for 'Itinerary' by taking help of search engine 'DuckDuckGo'
|
49 |
+
itinerary = itinerary_chain.run(location=prompt,duration=duration,DuckDuckGo_Search=search_result,expense=budget,origin=origin)
|
50 |
+
|
51 |
+
# Executing the chains we created for 'Conveyance', 'Cuisines', 'Accomodation' by taking help of search engine 'DuckDuckGo'
|
52 |
+
conveyance = conveyance_chain.run(location=prompt,origin=origin,DuckDuckGo_Search=search_result)
|
53 |
+
hotel = accomodation_chain.run(itinerary=itinerary,DuckDuckGo_Search=search_result)
|
54 |
+
cuisine = cuisines_chain.run(itinerary=itinerary,DuckDuckGo_Search=search_result)
|
55 |
+
|
56 |
+
# Returning the output
|
57 |
+
return search_result,itinerary,conveyance,hotel,cuisine
|