Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,125 +1,61 @@
|
|
1 |
-
import openai
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
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 |
-
return common_buses
|
59 |
-
|
60 |
-
# Main Streamlit function
|
61 |
-
def main():
|
62 |
-
st.title("Dhaka Local Buses and Routes Finder with GPT Creativity")
|
63 |
-
|
64 |
-
# Fun Bus-Related Facts or Trivia Section
|
65 |
-
st.header("Ask GPT for Fun Bus Facts or Trivia!")
|
66 |
-
trivia_input = st.text_input("Ask a fun fact or trivia about Dhaka's local buses:")
|
67 |
-
if trivia_input:
|
68 |
-
trivia_response = generate_creative_content(f"Tell me an interesting fact or trivia about Dhaka's local buses.")
|
69 |
-
st.write(trivia_response)
|
70 |
-
|
71 |
-
# Route Optimization Suggestions Section
|
72 |
-
st.header("Route Optimization Suggestions")
|
73 |
-
start_location = st.text_input("Enter your starting location (e.g., Mirpur):")
|
74 |
-
destination_location = st.text_input("Enter your destination location (e.g., Dhaka University):")
|
75 |
-
if start_location and destination_location:
|
76 |
-
# Get buses that pass through both the start and destination locations
|
77 |
-
buses_with_common_routes = get_buses_between_locations(start_location, destination_location)
|
78 |
-
|
79 |
-
if not buses_with_common_routes.empty:
|
80 |
-
st.write(f"Suggested buses from **{start_location}** to **{destination_location}**:")
|
81 |
-
for idx, row in buses_with_common_routes.iterrows():
|
82 |
-
st.write(f"- **{row['Dhaka Local Buses']}**: {clean_route(row['Routes'])}")
|
83 |
-
else:
|
84 |
-
st.write(f"No buses found passing through both **{start_location}** and **{destination_location}**.")
|
85 |
-
|
86 |
-
# Bus-Themed Storytelling Section
|
87 |
-
st.header("Create a Bus-Themed Story!")
|
88 |
-
story_input = st.text_input("Enter a location (e.g., Mirpur to Gabtoli) to create a bus-themed story:")
|
89 |
-
if story_input:
|
90 |
-
story_prompt = f"Create a short story about a passenger taking a bus from {story_input}."
|
91 |
-
bus_story = generate_creative_content(story_prompt)
|
92 |
-
st.write(bus_story)
|
93 |
-
|
94 |
-
# General Questions about Local Buses
|
95 |
-
st.header("Ask General Questions About Dhaka's Local Buses")
|
96 |
-
question_input = st.text_input("Ask a question about the Dhaka bus system (e.g., most common issues faced by commuters):")
|
97 |
-
if question_input:
|
98 |
-
question_answer = generate_creative_content(f"Answer the question: {question_input} about Dhaka's local buses.")
|
99 |
-
st.write(question_answer)
|
100 |
-
|
101 |
-
# Existing bus search functionality (unchanged)
|
102 |
-
st.header("Search Bus Name")
|
103 |
-
bus_name_options = ['Select Bus Name from dropdown'] + df['Dhaka Local Buses'].tolist()
|
104 |
-
bus_name = st.selectbox('Select a Bus Name', bus_name_options)
|
105 |
-
if bus_name != 'Select Bus Name from dropdown':
|
106 |
-
route = get_route_by_bus(bus_name)
|
107 |
-
st.write(f"Routes for **{bus_name}**:")
|
108 |
-
st.write(route)
|
109 |
else:
|
110 |
-
st.write("
|
111 |
-
|
112 |
-
# Location search functionality remains as before
|
113 |
-
st.header("Search Location")
|
114 |
-
location = st.text_input('Enter a location (e.g., Gabtoli, Mirpur)', '').strip()
|
115 |
-
if location:
|
116 |
-
buses = search_by_location(location)
|
117 |
-
if not buses.empty:
|
118 |
-
st.write(f"Buses passing through **{location}**:")
|
119 |
-
for idx, row in buses.iterrows():
|
120 |
-
st.write(f"- {row['Dhaka Local Buses']}: {clean_route(row['Routes'])}")
|
121 |
-
else:
|
122 |
-
st.write(f"No buses found for the location '**{location}**.")
|
123 |
|
124 |
-
|
125 |
-
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
|
4 |
+
# Load the Excel file into a DataFrame (adjust the file path accordingly)
|
5 |
+
df = pd.read_excel('Book1.xlsx')
|
6 |
+
|
7 |
+
# Clean up the DataFrame (strip any unnecessary whitespaces in column names)
|
8 |
+
df.columns = df.columns.str.strip()
|
9 |
+
|
10 |
+
# Function to clean routes and remove unwanted characters
|
11 |
+
def clean_route(route):
|
12 |
+
# Remove the "_x000D_" carriage return issue and other unwanted characters
|
13 |
+
return route.replace("_x000D_", "").strip()
|
14 |
+
|
15 |
+
# Function to search buses by location
|
16 |
+
def search_by_location(location):
|
17 |
+
# Filter buses that have the location in their routes
|
18 |
+
buses_with_location = df[df['Routes'].str.contains(location, case=False, na=False)]
|
19 |
+
return buses_with_location
|
20 |
+
|
21 |
+
# Function to get the route of a selected bus
|
22 |
+
def get_route_by_bus(bus_name):
|
23 |
+
# Get the route for the selected bus
|
24 |
+
bus_route = df[df['Dhaka Local Buses'] == bus_name]['Routes'].values
|
25 |
+
if len(bus_route) > 0:
|
26 |
+
return clean_route(bus_route[0]) # Clean the route before returning
|
27 |
+
else:
|
28 |
+
return "No route found for this bus."
|
29 |
+
|
30 |
+
# Streamlit app
|
31 |
+
def main():
|
32 |
+
st.title("Dhaka Local Buses and Routes Finder")
|
33 |
+
|
34 |
+
# Bus Name Search Section
|
35 |
+
st.header("Search Bus Name")
|
36 |
+
|
37 |
+
# Add a placeholder as the default option for the selectbox
|
38 |
+
bus_name = st.selectbox(
|
39 |
+
'Select a Bus Name from dropdown',
|
40 |
+
['Select Bus Name from dropdown'] + df['Dhaka Local Buses'].tolist() # Adding the placeholder at the beginning
|
41 |
+
)
|
42 |
+
|
43 |
+
if bus_name != 'Select Bus Name from dropdown': # Proceed only if a valid bus is selected
|
44 |
+
route = get_route_by_bus(bus_name)
|
45 |
+
st.write(f"Routes for **{bus_name}**:")
|
46 |
+
st.write(route)
|
47 |
+
|
48 |
+
# Location Search Section
|
49 |
+
st.header("Search Location")
|
50 |
+
location = st.text_input('Enter a location (e.g., Gabtoli, Mirpur)', '').strip()
|
51 |
+
if location:
|
52 |
+
buses = search_by_location(location)
|
53 |
+
if not buses.empty:
|
54 |
+
st.write(f"Buses passing through **{location}**:")
|
55 |
+
for idx, row in buses.iterrows():
|
56 |
+
st.write(f"- {row['Dhaka Local Buses']}: {clean_route(row['Routes'])}") # Clean routes before displaying
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
else:
|
58 |
+
st.write(f"No buses found for the location '**{location}**'.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
+
if __name__ == "__main__":
|
61 |
+
main()
|