Shubhy commited on
Commit
a0726c8
1 Parent(s): 0b16d03

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from bs4 import BeautifulSoup
4
+
5
+
6
+ def search_web(topic):
7
+ url = "https://www.example.com/search"
8
+ params = {
9
+ "q": topic,
10
+ "sort": "relevance",
11
+ "lang": "en"
12
+ }
13
+ response = requests.get(url, params=params)
14
+ soup = BeautifulSoup(response.content, "html.parser")
15
+ search_results = soup.find_all("div", class_="search-result")
16
+ return search_results
17
+
18
+
19
+ def get_best_path(starting_country, starting_city, destination_country, destination_city, transportation_mode, time_constraints, demographics, safety_concerns):
20
+ topics = ["refugee", "conflict", "blockade", "civil war", "Syria", "Ukraine"]
21
+
22
+ news_articles = []
23
+ for topic in topics:
24
+ search_results = search_web(topic)
25
+ for result in search_results:
26
+ title = result.find("h2").text
27
+ content = result.find("p").text
28
+ news_articles.append({"title": title, "content": content})
29
+
30
+ relevant_articles = []
31
+ for article in news_articles:
32
+ if (
33
+ starting_country.lower() in article["title"].lower()
34
+ and starting_city.lower() in article["title"].lower()
35
+ and destination_country.lower() in article["title"].lower()
36
+ and destination_city.lower() in article["title"].lower()
37
+ ):
38
+ relevant_articles.append(article)
39
+
40
+ if relevant_articles:
41
+ latest_article = relevant_articles[0]
42
+ latest_title = latest_article["title"]
43
+ latest_content = latest_article["content"]
44
+ else:
45
+ latest_title = ""
46
+ latest_content = ""
47
+
48
+ 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}"
49
+
50
+ 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."
51
+
52
+ # Perform further processing or use a different AI model to generate the response
53
+
54
+ output = "This is a placeholder response. Further processing is required."
55
+
56
+ return output
57
+
58
+
59
+ def main():
60
+ st.title("Best Path for Refugees")
61
+ starting_country = st.text_input("Starting Country")
62
+ starting_city = st.text_input("Starting City")
63
+ destination_country = st.text_input("Destination Country")
64
+ destination_city = st.text_input("Destination City")
65
+ transportation_mode = st.radio("Preferred Mode of Transportation", ["Land", "Air", "Sea", "All"])
66
+ time_constraints = st.text_input("Time Constraints")
67
+ demographics = st.text_input("Demographics")
68
+ safety_concerns = st.text_input("Safety Concerns")
69
+
70
+ if st.button("Get Best Path"):
71
+ output = get_best_path(starting_country, starting_city, destination_country, destination_city, transportation_mode, time_constraints, demographics, safety_concerns)
72
+ st.markdown(output)
73
+
74
+
75
+ if __name__ == "__main__":
76
+ main()