-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
194 lines (170 loc) · 8.01 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import os
import pytz
import streamlit as st
import json
from groq import Groq
from email_service import send_email # Import the email service
from datetime import datetime
# Initialize Groq client with your API key
client = Groq(api_key=st.secrets["GROQ_API_KEY"])
# Set page configuration to wide layout
st.set_page_config(page_title="Place Info with Groq", page_icon="🗺️", layout="wide")
# Hide the Streamlit header and footer
st.markdown("""
<style>
/* Hide header and footer */
header {visibility: hidden;}
footer {visibility: hidden;}
/* Background Image */
body {
background-image: url('https://user-images.githubusercontent.com/35409648/74775140-0373ab80-528d-11ea-8acd-9499c85a697f.gif'); /* Add your background image URL */
background-size: cover;
background-repeat: no-repeat;
animation: backgroundAnimation 30s infinite alternate;
}
/* Keyframes for Animation */
@keyframes backgroundAnimation {
0% { opacity: 1; }
100% { opacity: 0.7; } /* Adjust opacity for the animation effect */
}
/* Container styling */
.container {
width: 90%;
margin: auto;
background-color: rgba(255, 255, 255, 0.8); /* Semi-transparent white background */
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
</style>
""", unsafe_allow_html=True)
# Title and Description
# st.markdown("<div class='container'>", unsafe_allow_html=True) # Start of container
st.title("Get Information About Any Place 🗺️")
st.write("Enter the name of a place to get interesting details about it.")
# Function to generate greeting based on the time of day
# Function to generate greeting based on the user's time zone
def get_greeting():
# Get the current time in the user's time zone
tz = pytz.timezone("Asia/Kolkata")
current_time = datetime.now(tz)
current_hour = current_time.hour
current_day = current_time.strftime("%A")
# Determine greeting based on current hour
if 5 <= current_hour < 12:
greeting = "Good Morning"
elif 12 <= current_hour < 17:
greeting = "Good Afternoon"
elif 17 <= current_hour < 21:
greeting = "Good Evening"
else:
greeting = "Good Night"
return f"{greeting}, Happy {current_day}!"
# Display greeting
st.markdown(f"<h3 style='color:orange;'>{get_greeting()}</h3>", unsafe_allow_html=True)
# User Input with Typing Animation
placeholder_text = "Hy Boss, type here !!!"
place_name = st.text_input("Enter Place Name", placeholder=placeholder_text)
# Function to get details from Groq with different questions
def get_place_details(place):
questions = {
"historical_facts": f"Tell me about the historical significance of {place}.",
"attractions": f"What are the main attractions in {place}?",
"famous_places": f"Which famous places should I not miss in {place}?",
"unique_information": f"Share some unique information about {place}."
}
place_info = {"place": place}
for field, question in questions.items():
response = client.chat.completions.create(
messages=[{"role": "user", "content": question}],
model="llama3-8b-8192"
)
place_info[field] = response.choices[0].message.content if response.choices else "No details found."
return place_info
# Button to submit the place name
if st.button("Get Details"):
if place_name:
with st.spinner("Fetching details..."):
try:
details = get_place_details(place_name)
st.success("Here are the details:")
# Display details with styled headers for the user
st.markdown(f"<span style='font-weight:bold; color:orange;'>Historical Facts</span>: {details['historical_facts']}", unsafe_allow_html=True)
st.markdown(f"<span style='font-weight:bold; color:orange;'>Attractions</span>: {details['attractions']}", unsafe_allow_html=True)
st.markdown(f"<span style='font-weight:bold; color:orange;'>Famous Places</span>: {details['famous_places']}", unsafe_allow_html=True)
st.markdown(f"<span style='font-weight:bold; color:orange;'>Unique Information</span>: {details['unique_information']}", unsafe_allow_html=True)
json_data = json.dumps(details)
# HTML content for the email
html_content = f"""
<html>
<head>
<style>
body {{
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
}}
.container {{
width: 90%;
margin: 0 auto;
background-color: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}}
.header {{
text-align: center;
padding: 10px 0;
color: #4CAF50;
}}
.place-details {{
width: 100%;
margin-top: 20px;
border-collapse: collapse;
}}
.place-details th {{
background-color: #4CAF50;
color: white;
padding: 12px;
text-align: left;
border: 1px solid #ddd;
}}
.place-details td {{
padding: 12px;
border: 1px solid #ddd;
color: #555;
}}
.footer {{
text-align: center;
margin-top: 20px;
color: #888;
}}
</style>
</head>
<body>
<div class="container">
<h2 class="header">Place Information Request</h2>
<p>Here is the information you requested for <strong>{place_name}</strong>:</p>
<table class="place-details">
<tr><th>Field</th><th>Information</th></tr>
<tr><td><strong>Historical Facts</strong></td><td>{details["historical_facts"]}</td></tr>
<tr><td><strong>Attractions</strong></td><td>{details["attractions"]}</td></tr>
<tr><td><strong>Famous Places</strong></td><td>{details["famous_places"]}</td></tr>
<tr><td><strong>Unique Information</strong></td><td>{details["unique_information"]}</td></tr>
</table>
<div class="footer"><p>Thank you for using our service!</p><p>Made with ❤️ using Streamlit and Groq</p></div>
</div>
</body>
</html>
"""
subject = f"Place Info Request: {place_name}"
# Send email with the HTML content
# send_email(subject, html_content)
except Exception as e:
st.error(f"Error fetching details: {e}")
# Close the container
st.markdown("</div>", unsafe_allow_html=True) # End of container
# Footer
st.markdown("---")
# st.write("Made with ❤️ using Streamlit and Groq By Chinmay Jena")
st.write("Made By Chinmay Jena")