Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
# Read the CSV data | |
data = pd.read_csv("integrated_travel_data.csv") | |
def get_city_info(city): | |
city_data = data[data['Destination'].str.lower().str.strip() == city.lower().strip()] | |
if city_data.empty: | |
return "City not found in the database." | |
city_info = city_data.iloc[0] | |
info = f"Destination: {city_info['Destination']}\n" | |
info += f"State: {city_info['State']}\n\n" | |
info += f"Description: {city_info['Description']}\n\n" | |
info += "Tourist Attractions:\n" | |
attractions = city_info['Tourist Attractions'].split(', ') | |
for attraction in attractions: | |
info += f"- {attraction}\n" | |
info += "\nActivities:\n" | |
activities = city_info['Activities'].split('. ') | |
for activity in activities: | |
info += f"- {activity}\n" | |
return info | |
def list_places_by_state(state): | |
state_data = data[data['State'].str.lower().str.strip() == state.lower().strip()] | |
if state_data.empty: | |
return f"No destinations found for {state}." | |
places = state_data['Destination'].tolist() | |
return f"Destinations in {state}:\n" + "\n".join(places) | |
# Create the Gradio interface | |
with gr.Blocks() as iface: | |
gr.Markdown("# Indian Travel Information") | |
gr.Markdown("Enter a state to see available destinations, then enter a city name for detailed information.") | |
with gr.Row(): | |
with gr.Column(): | |
state_input = gr.Textbox(label="Enter state name") | |
state_output = gr.Textbox(label="Destinations in State", lines=10) | |
gr.Examples( | |
examples=[ | |
["Uttar Pradesh"], | |
["Maharashtra"], | |
["Rajasthan"], | |
["Arunachal Pradesh"], | |
["Assam"] | |
], | |
inputs=state_input | |
) | |
with gr.Column(): | |
city_input = gr.Textbox(label="Enter city name") | |
submit_button = gr.Button("Submit") | |
city_info_output = gr.Textbox(label="City Information", lines=20) | |
gr.Examples( | |
examples=[ | |
["Agra"], | |
["Mumbai"], | |
["Jaipur"], | |
["Tawang"], | |
["Guwahati"] | |
], | |
inputs=city_input | |
) | |
state_input.change(list_places_by_state, inputs=state_input, outputs=state_output) | |
submit_button.click(get_city_info, inputs=city_input, outputs=city_info_output) | |
iface.launch() |