Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +25 -76
- requirements.txt +0 -1
app.py
CHANGED
@@ -45,8 +45,6 @@ os.environ['SERPAPI_API_KEY']='2e3312eee2ce5e3d9d97989c87999ae121765134a5f713b91
|
|
45 |
from langchain_community.utilities import SerpAPIWrapper
|
46 |
# search = SerpAPIWrapper()
|
47 |
|
48 |
-
import trafilatura
|
49 |
-
|
50 |
# from google.colab import userdata
|
51 |
# groq_api_key = userdata.get('GROQ_API_KEY')
|
52 |
# api_key = userdata.get('twelvelabs')
|
@@ -235,67 +233,31 @@ from langchain_community.document_loaders import WebBaseLoader
|
|
235 |
# return docs
|
236 |
|
237 |
|
238 |
-
|
239 |
-
|
240 |
-
# tool = TavilySearchResults(max_results=5)
|
241 |
-
# resp =tool.invoke({"query": f"Tell me about tourist destination place called: {destination}"})
|
242 |
-
# urls = [result['url'] for result in resp]
|
243 |
-
# print("urls ",urls)
|
244 |
-
|
245 |
-
|
246 |
-
# essay = llamaver.invoke(f"You are a great travel advisor. Write an insightful and helpful essay for a traveller who plans to visit {destination}")
|
247 |
-
# essaydoc = Document(page_content=essay.content)
|
248 |
-
|
249 |
-
# cont = []
|
250 |
-
# cont.append(essaydoc)
|
251 |
-
|
252 |
-
# for url in urls:
|
253 |
-
# try:
|
254 |
-
# downloaded = trafilatura.fetch_url(url)
|
255 |
-
# text = trafilatura.extract(downloaded) #, config=trafilatura_config)
|
256 |
-
# except Exception:
|
257 |
-
# pass
|
258 |
-
# txt = Document(page_content = text)
|
259 |
-
# cont.append(txt)
|
260 |
-
|
261 |
-
# # docs=[]
|
262 |
-
# # docs.append(essaydoc)
|
263 |
-
# # for url in urls:
|
264 |
-
# # if "youtube.com" not in url:
|
265 |
-
# # loader = WebBaseLoader(url)
|
266 |
-
# # try:
|
267 |
-
# # docs1 = loader.load()
|
268 |
-
# # docs.extend(docs1)
|
269 |
-
# # except Exception:
|
270 |
-
# # pass
|
271 |
-
|
272 |
-
# print("docs created")
|
273 |
-
# return cont
|
274 |
-
|
275 |
-
|
276 |
-
def get_docs(destination,prompt):
|
277 |
|
278 |
tool = TavilySearchResults(max_results=5)
|
279 |
-
resp =tool.invoke({"query": f"{
|
280 |
urls = [result['url'] for result in resp]
|
281 |
print("urls ",urls)
|
282 |
|
283 |
|
284 |
-
|
285 |
-
|
286 |
|
287 |
-
cont = []
|
288 |
-
# cont.append(essaydoc)
|
289 |
|
|
|
|
|
290 |
for url in urls:
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
|
|
|
|
299 |
|
300 |
from langchain import hub
|
301 |
from langchain.chains.combine_documents.stuff import StuffDocumentsChain
|
@@ -307,7 +269,7 @@ from langchain_text_splitters import CharacterTextSplitter
|
|
307 |
|
308 |
from duckduckgo_search import DDGS
|
309 |
|
310 |
-
def get_blogsummary(docs
|
311 |
|
312 |
# Map
|
313 |
map_template = """The following is a set of documents. \
|
@@ -442,17 +404,16 @@ def get_transcriptsummary(docs):
|
|
442 |
|
443 |
|
444 |
|
445 |
-
def get_summary(destination,vlogsummary
|
446 |
-
|
447 |
-
|
|
|
448 |
|
449 |
-
prompt = f"Tell me about the tourist destination place called {destination}"
|
450 |
-
docs = get_docs(destination, prompt)
|
451 |
if vlogsummary:
|
452 |
vlog_doc = Document(page_content=vlogsummary)
|
453 |
docs.append(vlog_doc)
|
454 |
|
455 |
-
summary = get_blogsummary(docs
|
456 |
|
457 |
return summary
|
458 |
|
@@ -639,12 +600,6 @@ def get_traveladvisory(origin, destination,prompt,llm):
|
|
639 |
##########################################################################################
|
640 |
##########################################################################################
|
641 |
|
642 |
-
def get_info(destination,prompt,llm):
|
643 |
-
docs = get_docs(destination,prompt)
|
644 |
-
print("get info docs obtained")
|
645 |
-
info = get_blogsummary(destination,llm)
|
646 |
-
return info
|
647 |
-
|
648 |
# Functions called by gradio
|
649 |
|
650 |
def travel_advisory(origin, selection, custom_input,days, purpose):
|
@@ -708,19 +663,13 @@ def travel_advisory(origin, selection, custom_input,days, purpose):
|
|
708 |
image = get_image_url(destination)
|
709 |
# print("image extracted")
|
710 |
|
711 |
-
|
712 |
-
|
713 |
|
714 |
-
general = get_info(destination,general_pr,llm)
|
715 |
-
print("general info obtained")
|
716 |
-
|
717 |
places = get_traveladvisory(origin,destination,places_pr,llama70)
|
718 |
print("interesting places obtained")
|
719 |
|
720 |
-
|
721 |
-
# print("weather obtained")
|
722 |
-
|
723 |
-
weather = get_info(destination,weather_pr,llm)
|
724 |
print("weather obtained")
|
725 |
|
726 |
politics = get_traveladvisory(origin,destination,politics_pr,llmgemma)
|
|
|
45 |
from langchain_community.utilities import SerpAPIWrapper
|
46 |
# search = SerpAPIWrapper()
|
47 |
|
|
|
|
|
48 |
# from google.colab import userdata
|
49 |
# groq_api_key = userdata.get('GROQ_API_KEY')
|
50 |
# api_key = userdata.get('twelvelabs')
|
|
|
233 |
# return docs
|
234 |
|
235 |
|
236 |
+
def get_docs(destination):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
|
238 |
tool = TavilySearchResults(max_results=5)
|
239 |
+
resp =tool.invoke({"query": f"Tell me about tourist destination place called: {destination}"})
|
240 |
urls = [result['url'] for result in resp]
|
241 |
print("urls ",urls)
|
242 |
|
243 |
|
244 |
+
essay = llamaver.invoke(f"You are a great travel advisor. Write an insightful and helpful essay for a traveller who plans to visit {destination}")
|
245 |
+
essaydoc = Document(page_content=essay.content)
|
246 |
|
|
|
|
|
247 |
|
248 |
+
docs=[]
|
249 |
+
docs.append(essaydoc)
|
250 |
for url in urls:
|
251 |
+
if "youtube.com" not in url:
|
252 |
+
loader = WebBaseLoader(url)
|
253 |
+
try:
|
254 |
+
docs1 = loader.load()
|
255 |
+
docs.extend(docs1)
|
256 |
+
except Exception:
|
257 |
+
pass
|
258 |
+
print("docs created")
|
259 |
+
return docs
|
260 |
+
|
261 |
|
262 |
from langchain import hub
|
263 |
from langchain.chains.combine_documents.stuff import StuffDocumentsChain
|
|
|
269 |
|
270 |
from duckduckgo_search import DDGS
|
271 |
|
272 |
+
def get_blogsummary(docs):
|
273 |
|
274 |
# Map
|
275 |
map_template = """The following is a set of documents. \
|
|
|
404 |
|
405 |
|
406 |
|
407 |
+
def get_summary(destination,vlogsummary):
|
408 |
+
docs = get_docs(destination)
|
409 |
+
|
410 |
+
print("blog docs obtained")
|
411 |
|
|
|
|
|
412 |
if vlogsummary:
|
413 |
vlog_doc = Document(page_content=vlogsummary)
|
414 |
docs.append(vlog_doc)
|
415 |
|
416 |
+
summary = get_blogsummary(docs)
|
417 |
|
418 |
return summary
|
419 |
|
|
|
600 |
##########################################################################################
|
601 |
##########################################################################################
|
602 |
|
|
|
|
|
|
|
|
|
|
|
|
|
603 |
# Functions called by gradio
|
604 |
|
605 |
def travel_advisory(origin, selection, custom_input,days, purpose):
|
|
|
663 |
image = get_image_url(destination)
|
664 |
# print("image extracted")
|
665 |
|
666 |
+
general = get_traveladvisory(origin,destination,general_pr,llm)
|
667 |
+
print("general adv obtained")
|
668 |
|
|
|
|
|
|
|
669 |
places = get_traveladvisory(origin,destination,places_pr,llama70)
|
670 |
print("interesting places obtained")
|
671 |
|
672 |
+
weather = get_traveladvisory(origin,destination,weather_pr,llm)
|
|
|
|
|
|
|
673 |
print("weather obtained")
|
674 |
|
675 |
politics = get_traveladvisory(origin,destination,politics_pr,llmgemma)
|
requirements.txt
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
trafilatura
|
2 |
langchain
|
3 |
langchain-groq
|
4 |
langchainhub
|
|
|
|
|
1 |
langchain
|
2 |
langchain-groq
|
3 |
langchainhub
|