Files changed (1) hide show
  1. app.py +0 -104
app.py DELETED
@@ -1,104 +0,0 @@
1
- import streamlit as st
2
- import requests
3
- from fpdf import FPDF
4
- import os
5
- from dotenv import load_dotenv
6
- from datetime import datetime
7
- import zipfile
8
-
9
- # Langchain Imports
10
- from langchain.memory import ConversationBufferMemory
11
- from langchain.chains import ConversationChain
12
- from langchain_community.llms import HuggingFaceHub
13
-
14
-
15
- # πŸ”“ Extract .streamlit folder if zipped
16
- if not os.path.exists(".streamlit"):
17
- with zipfile.ZipFile(".streamlit.zip", 'r') as zip_ref:
18
- zip_ref.extractall(".")
19
-
20
- # βœ… Load .env variables
21
- load_dotenv()
22
- HF_API_TOKEN = os.getenv("HF_API_TOKEN")
23
-
24
- # βœ… Initialize LangChain LLM
25
- llm = HuggingFaceHub(
26
- repo_id="mistralai/Mistral-7B-Instruct-v0.1",
27
- model_kwargs={"temperature": 0.7, "max_new_tokens": 2048},
28
- huggingfacehub_api_token=HF_API_TOKEN
29
- )
30
-
31
- # βœ… Setup LangChain memory and conversation
32
- if "memory" not in st.session_state:
33
- st.session_state.memory = ConversationBufferMemory()
34
- if "conversation" not in st.session_state:
35
- st.session_state.conversation = ConversationChain(
36
- llm=llm,
37
- memory=st.session_state.memory,
38
- verbose=False
39
- )
40
-
41
- # βœ… PDF generation function
42
- def save_trip_plan_as_pdf(text, filename="trip_plan.pdf"):
43
- pdf = FPDF()
44
- pdf.add_page()
45
- pdf.set_font("Arial", size=12)
46
- safe_text = text.encode('latin-1', 'ignore').decode('latin-1')
47
- pdf.multi_cell(0, 10, safe_text)
48
- pdf.output(filename)
49
-
50
- # βœ… Streamlit UI
51
- st.set_page_config(page_title="Intelligent Travel Planner", layout="wide")
52
- st.title("🧳 Intelligent Travel Planner Agent")
53
-
54
- # 🎯 User inputs
55
- col1, col2 = st.columns(2)
56
- with col1:
57
- from_location = st.text_input("🏠 Your Current Location", placeholder="e.g., Mumbai")
58
- destination = st.text_input("🌍 Destination", placeholder="e.g., Manali")
59
- start_date = st.date_input("πŸ“… Start Date")
60
- with col2:
61
- end_date = st.date_input("πŸ“… End Date")
62
- budget = st.text_input("πŸ’° Budget (in INR)", placeholder="e.g., 5000")
63
- preferences = st.text_input("🎯 Preferences", placeholder="e.g., Adventure, Culture, Beaches")
64
-
65
- generate_button = st.button("✈️ Generate Trip Plan")
66
-
67
- # βœ… Generate and display AI trip plan
68
- if generate_button:
69
- if from_location and destination and budget and preferences and start_date and end_date:
70
- user_prompt = (
71
- f"Create a detailed day-wise travel itinerary with for a trip to {destination} in India. "
72
- f"The trip should start on {start_date.strftime('%B %d, %Y')} and end on {end_date.strftime('%B %d, %Y')}, "
73
- f"with a total budget of β‚Ή{budget} INR. The traveler prefers {preferences.lower()} experiences. \n\n"
74
- f"Provide a **day-wise breakdown** of the trip including:\n"
75
- f"- Top tourist attractions\n"
76
- f"- Recommended local food\n"
77
- f"- Suggested experiences (markets, nature, etc.)\n"
78
- f"- Approximate daily expenses\n\n"
79
- f"Make sure the total plan is budget-friendly and culturally immersive. End with final tips."
80
- )
81
-
82
- with st.spinner("🧠 Generating trip plan..."):
83
- ai_response = st.session_state.conversation.run(user_prompt)
84
-
85
- st.subheader("πŸ“‹ Your AI-Generated Trip Plan")
86
- st.write(ai_response)
87
-
88
- save_trip_plan_as_pdf(ai_response)
89
- with open("trip_plan.pdf", "rb") as f:
90
- st.download_button("πŸ“„ Download as PDF", f, file_name="trip_plan.pdf")
91
-
92
- else:
93
- st.warning("🚨 Please fill out all fields above.")
94
-
95
- # 🧠 Follow-up Chat Section
96
- st.markdown("---")
97
- st.subheader("πŸ’¬ Ask Follow-Up Questions")
98
- follow_up = st.text_input("Ask a follow-up about your trip plan")
99
-
100
- if follow_up:
101
- with st.spinner("πŸ’‘ Thinking..."):
102
- response = st.session_state.conversation.run(follow_up)
103
- st.markdown(f"**AI:** {response}")
104
-