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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import time
|
| 4 |
+
import folium
|
| 5 |
+
from folium import plugins
|
| 6 |
+
import pandas as pd
|
| 7 |
+
from streamlit.components.v1 import html
|
| 8 |
+
from groq import Groq
|
| 9 |
+
|
| 10 |
+
# Initialize Groq client with your API key
|
| 11 |
+
client = Groq(api_key="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")
|
| 12 |
+
|
| 13 |
+
# Set up the title and description for the Streamlit app
|
| 14 |
+
st.set_page_config(page_title="Gaia: Women Safety App", page_icon="🤖", layout="centered")
|
| 15 |
+
|
| 16 |
+
# Function to get AI response (Groq model)
|
| 17 |
+
def get_response(user_input):
|
| 18 |
+
"""Get response from Groq AI model."""
|
| 19 |
+
if 'messages' not in st.session_state:
|
| 20 |
+
st.session_state['messages'] = []
|
| 21 |
+
|
| 22 |
+
st.session_state['messages'].append({"role": "user", "content": user_input})
|
| 23 |
+
|
| 24 |
+
# Call Groq API to get the AI's response
|
| 25 |
+
chat_completion = client.chat.completions.create(
|
| 26 |
+
messages=st.session_state['messages'],
|
| 27 |
+
model="llama3-8b-8192" # Specify model you want to use from Groq
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
ai_message = chat_completion.choices[0].message.content
|
| 31 |
+
st.session_state['messages'].append({"role": "assistant", "content": ai_message})
|
| 32 |
+
|
| 33 |
+
return ai_message
|
| 34 |
+
|
| 35 |
+
# Sidebar for navigation
|
| 36 |
+
st.sidebar.title('Features')
|
| 37 |
+
page = st.sidebar.radio("Choose a feature", ["Personal Information", "AI-Powered Support", "Emergency Call", "Dangerous Area Map", "ORS Route"])
|
| 38 |
+
|
| 39 |
+
# Personal Information Page (First Page)
|
| 40 |
+
if page == "Personal Information":
|
| 41 |
+
st.title("Personal Information Page")
|
| 42 |
+
st.write("Please fill in the following details:")
|
| 43 |
+
|
| 44 |
+
with st.form(key='personal_info_form'):
|
| 45 |
+
full_name = st.text_input("Full Name")
|
| 46 |
+
country = st.text_input("Country")
|
| 47 |
+
age = st.number_input("Age", min_value=0, max_value=120, value=25)
|
| 48 |
+
gender = st.radio("Gender", ('Male', 'Female', 'Other'))
|
| 49 |
+
email = st.text_input("Email Address")
|
| 50 |
+
phone_number = st.text_input("Phone Number")
|
| 51 |
+
address = st.text_area("Address")
|
| 52 |
+
|
| 53 |
+
submit_button = st.form_submit_button(label='Submit')
|
| 54 |
+
|
| 55 |
+
if submit_button:
|
| 56 |
+
st.subheader("Your Personal Information:")
|
| 57 |
+
st.write(f"**Full Name:** {full_name}")
|
| 58 |
+
st.write(f"**Country:** {country}")
|
| 59 |
+
st.write(f"**Age:** {age}")
|
| 60 |
+
st.write(f"**Gender:** {gender}")
|
| 61 |
+
st.write(f"**Email:** {email}")
|
| 62 |
+
st.write(f"**Phone Number:** {phone_number}")
|
| 63 |
+
st.write(f"**Address:** {address}")
|
| 64 |
+
st.write("Thank you for sharing your details! You can now access the app's features.")
|
| 65 |
+
|
| 66 |
+
# AI-Powered Support Page
|
| 67 |
+
elif page == "AI-Powered Support":
|
| 68 |
+
st.header("Simulate a Call with Gaia AI")
|
| 69 |
+
user_input = st.text_input("Tell Gaia how you're feeling:", "")
|
| 70 |
+
|
| 71 |
+
if user_input:
|
| 72 |
+
ai_response = get_response(user_input)
|
| 73 |
+
st.markdown(f"**Gaia (AI):** {ai_response}")
|
| 74 |
+
|
| 75 |
+
# Emergency Call Page
|
| 76 |
+
elif page == "Emergency Call":
|
| 77 |
+
st.header("Emergency Call Simulation")
|
| 78 |
+
|
| 79 |
+
emergency_button = st.button("Call Emergency Services")
|
| 80 |
+
|
| 81 |
+
if emergency_button:
|
| 82 |
+
with st.spinner('Connecting to emergency services...'):
|
| 83 |
+
time.sleep(2) # Simulating a short delay
|
| 84 |
+
st.success("Emergency services have been contacted. Help is on the way!")
|
| 85 |
+
st.write("You will receive assistance shortly. Stay safe!")
|
| 86 |
+
|
| 87 |
+
# Dangerous Area Map Page
|
| 88 |
+
elif page == "Dangerous Area Map":
|
| 89 |
+
st.header("Dangerous Area Map (Prototype)")
|
| 90 |
+
|
| 91 |
+
data = {
|
| 92 |
+
'latitude': [40.7128, 34.0522, 51.5074, 48.8566, 35.6762],
|
| 93 |
+
'longitude': [-74.0060, -118.2437, -0.1278, 2.3522, 139.6503],
|
| 94 |
+
'area': ['New York', 'Los Angeles', 'London', 'Paris', 'Tokyo'],
|
| 95 |
+
'danger_level': ['High', 'Medium', 'Low', 'High', 'Medium']
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
df = pd.DataFrame(data)
|
| 99 |
+
map_center = [df['latitude'].mean(), df['longitude'].mean()]
|
| 100 |
+
m = folium.Map(location=map_center, zoom_start=2)
|
| 101 |
+
|
| 102 |
+
def get_color(danger_level):
|
| 103 |
+
if danger_level == 'High':
|
| 104 |
+
return 'red'
|
| 105 |
+
elif danger_level == 'Medium':
|
| 106 |
+
return 'orange'
|
| 107 |
+
else:
|
| 108 |
+
return 'green'
|
| 109 |
+
|
| 110 |
+
for index, row in df.iterrows():
|
| 111 |
+
danger_color = get_color(row['danger_level'])
|
| 112 |
+
folium.CircleMarker(
|
| 113 |
+
location=[row['latitude'], row['longitude']],
|
| 114 |
+
radius=10,
|
| 115 |
+
color=danger_color,
|
| 116 |
+
fill=True,
|
| 117 |
+
fill_color=danger_color,
|
| 118 |
+
fill_opacity=0.7,
|
| 119 |
+
popup=f"Area: {row['area']}<br> Danger Level: {row['danger_level']}"
|
| 120 |
+
).add_to(m)
|
| 121 |
+
|
| 122 |
+
heat_data = [[row['latitude'], row['longitude']] for index, row in df.iterrows()]
|
| 123 |
+
plugins.HeatMap(heat_data).add_to(m)
|
| 124 |
+
|
| 125 |
+
st.subheader("Dangerous Areas Map")
|
| 126 |
+
st.write("This map visualizes areas with different danger levels.")
|
| 127 |
+
st.markdown("Use the color code to interpret the danger level:")
|
| 128 |
+
st.markdown("🟥 High | 🟧 Medium | 🟩 Low")
|
| 129 |
+
|
| 130 |
+
map_html = m._repr_html_()
|
| 131 |
+
html(map_html, height=500)
|
| 132 |
+
|
| 133 |
+
# ORS Route Page (New Page)
|
| 134 |
+
elif page == "ORS Route":
|
| 135 |
+
st.title("OpenRouteService: Route Calculator")
|
| 136 |
+
st.write("Enter your current location and destination to calculate the route:")
|
| 137 |
+
|
| 138 |
+
# User inputs for current location and destination
|
| 139 |
+
start_lat = st.number_input("Enter the latitude of the start point:", value=40.7128)
|
| 140 |
+
start_lon = st.number_input("Enter the longitude of the start point:", value=-74.0060)
|
| 141 |
+
end_lat = st.number_input("Enter the latitude of the destination:", value=34.0522)
|
| 142 |
+
end_lon = st.number_input("Enter the longitude of the destination:", value=-118.2437)
|
| 143 |
+
|
| 144 |
+
if st.button("Calculate Route"):
|
| 145 |
+
if start_lat and start_lon and end_lat and end_lon:
|
| 146 |
+
# OpenRouteService API key
|
| 147 |
+
api_key = '5b3ce3597851110001cf6248678e77a7fc474afbbb5ec203d721079c'
|
| 148 |
+
start_point = f'{start_lon},{start_lat}' # ORS expects lon, lat
|
| 149 |
+
end_point = f'{end_lon},{end_lat}'
|
| 150 |
+
|
| 151 |
+
# API request to OpenRouteService
|
| 152 |
+
url = f'https://api.openrouteservice.org/v2/directions/driving-car?api_key={api_key}&start={start_point}&end={end_point}'
|
| 153 |
+
response = requests.get(url)
|
| 154 |
+
|
| 155 |
+
if response.status_code == 200:
|
| 156 |
+
data = response.json()
|
| 157 |
+
# Extract the route information
|
| 158 |
+
route = data['features'][0]['geometry']['coordinates']
|
| 159 |
+
route_map = folium.Map(location=[start_lat, start_lon], zoom_start=12)
|
| 160 |
+
|
| 161 |
+
# Plot the route on the map
|
| 162 |
+
folium.PolyLine(locations=[(lat, lon) for lon, lat in route], color='blue', weight=5).add_to(route_map)
|
| 163 |
+
|
| 164 |
+
# Display the route map in the app
|
| 165 |
+
st.subheader("Calculated Route")
|
| 166 |
+
route_html = route_map._repr_html_()
|
| 167 |
+
html(route_html, height=500)
|
| 168 |
+
else:
|
| 169 |
+
st.error(f"Error: {response.status_code}")
|
| 170 |
+
else:
|
| 171 |
+
st.error("Please enter valid coordinates for both start and end locations.")
|
| 172 |
+
|
| 173 |
+
# Styling the chat window (Optional)
|
| 174 |
+
st.markdown("""
|
| 175 |
+
<style>
|
| 176 |
+
.css-1v3fvcr {
|
| 177 |
+
font-family: 'Arial', sans-serif;
|
| 178 |
+
background-color: #f0f2f6;
|
| 179 |
+
border-radius: 12px;
|
| 180 |
+
padding: 15px;
|
| 181 |
+
box-shadow: 0 0 20px rgba(0,0,0,0.1);
|
| 182 |
+
}
|
| 183 |
+
.css-15zrgwt {
|
| 184 |
+
font-size: 1.1rem;
|
| 185 |
+
line-height: 1.5;
|
| 186 |
+
}
|
| 187 |
+
.css-10hldgk {
|
| 188 |
+
font-size: 1rem;
|
| 189 |
+
}
|
| 190 |
+
</style>
|
| 191 |
+
""", unsafe_allow_html=True)
|