ReliefRouteDemo / app.py
Shubhy's picture
Create app.py
a0726c8
raw
history blame contribute delete
No virus
3.65 kB
import streamlit as st
import requests
from bs4 import BeautifulSoup
def search_web(topic):
url = "https://www.example.com/search"
params = {
"q": topic,
"sort": "relevance",
"lang": "en"
}
response = requests.get(url, params=params)
soup = BeautifulSoup(response.content, "html.parser")
search_results = soup.find_all("div", class_="search-result")
return search_results
def get_best_path(starting_country, starting_city, destination_country, destination_city, transportation_mode, time_constraints, demographics, safety_concerns):
topics = ["refugee", "conflict", "blockade", "civil war", "Syria", "Ukraine"]
news_articles = []
for topic in topics:
search_results = search_web(topic)
for result in search_results:
title = result.find("h2").text
content = result.find("p").text
news_articles.append({"title": title, "content": content})
relevant_articles = []
for article in news_articles:
if (
starting_country.lower() in article["title"].lower()
and starting_city.lower() in article["title"].lower()
and destination_country.lower() in article["title"].lower()
and destination_city.lower() in article["title"].lower()
):
relevant_articles.append(article)
if relevant_articles:
latest_article = relevant_articles[0]
latest_title = latest_article["title"]
latest_content = latest_article["content"]
else:
latest_title = ""
latest_content = ""
explanation = f"Based on the latest news article titled '{latest_title}', it has been considered in determining the best path for refugees from {starting_city}, {starting_country} to {destination_city}, {destination_country}. Here are the details: \n\n{latest_content}"
prompt = f"\nGiven the latest news on refugees, please provide the best path for refugees to travel from {starting_city}, {starting_country} to {destination_city}, {destination_country}. Please take into account any current conflicts or blockades in the region. Please provide a detailed list of the cities that they must pass through to reach their destination, along with their coordinates. \n\nLatest news on the exact refugee: \n- {latest_title} \n- {latest_content}\n\nExplanation based on the latest news:\n{explanation}\n\nPlease provide a comprehensive explanation of your reasoning, including the news articles and information you used to determine the best path. Format the response well with bullet points, headings, as well as spacing in between answers."
# Perform further processing or use a different AI model to generate the response
output = "This is a placeholder response. Further processing is required."
return output
def main():
st.title("Best Path for Refugees")
starting_country = st.text_input("Starting Country")
starting_city = st.text_input("Starting City")
destination_country = st.text_input("Destination Country")
destination_city = st.text_input("Destination City")
transportation_mode = st.radio("Preferred Mode of Transportation", ["Land", "Air", "Sea", "All"])
time_constraints = st.text_input("Time Constraints")
demographics = st.text_input("Demographics")
safety_concerns = st.text_input("Safety Concerns")
if st.button("Get Best Path"):
output = get_best_path(starting_country, starting_city, destination_country, destination_city, transportation_mode, time_constraints, demographics, safety_concerns)
st.markdown(output)
if __name__ == "__main__":
main()