SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files121234567891011121314151617181920212223242526527282989303132333435123637383940171819202122232425262728293031323334354142433738394041424344454647454647484950515253545556575859606162636465666768697048import streamlit as stimport pandas as pdimport requestsimport streamlit as stimport os# Tavily API Keyclient = Groq( api_key=os.environ.get("TAVILY_API_KEY"),)
# Function to fetch suggestions from Tavily APIdef fetch_tavily_suggestions(location, need): """ Use Tavily API to fetch real-time suggestions based on location and need. """ headers = {"Authorization": f"Bearer {TAVILY_API_KEY}"} prompt = f"Provide {need.lower()} recommendations for rural areas near {location}. Focus on affordability and accessibility." api_url = "https://api.tavily.ai/v1/generate"
payload = {"prompt": prompt, "model": "your-model-choice", "max_tokens": 300}
response = requests.post(api_url, headers=headers, json=payload) if response.status_code == 200: return response.json().get("text", "No recommendations available.") else: return f"Error: Unable to fetch data from Tavily API. Status code: {response.status_code}"
# Title and Description# Streamlit Appst.title("Rural Connectivity Advisor")st.markdown("""Welcome to the **Rural Connectivity Advisor**! This app helps rural communities find affordable internet solutions, boost connectivity, and access offline tools for education, healthcare, and business needs.Welcome to the **Rural Connectivity Advisor**! This app helps rural communities find:- Affordable internet solutions.- Signal boosting tips.- Offline tools for education, healthcare, and business.""")
# Sidebar Input# User Inputsst.sidebar.header("Input Your Details")location = st.sidebar.text_input("Enter Your Location (e.g., City, District)")needs = st.sidebar.selectbox("What do you need?", ["Internet Provider", "Signal Boosting Tips", "Offline Tools"])
# Placeholder for Internet Providers@st.cache_datadef fetch_providers(location): """Fetch a list of internet providers based on location (simulated data).""" # Simulated data (replace with a real API or database in the future) providers = { "satellite": [ {"name": "Starlink", "type": "Satellite", "cost": "$110/month", "coverage": "Global"}, {"name": "HughesNet", "type": "Satellite", "cost": "$60/month", "coverage": "North America"}, ], "local": [ {"name": "LocalNet Rural", "type": "Local ISP", "cost": "$40/month", "coverage": "Regional"}, ], } return providers
# Display Internet Providersif needs == "Internet Provider": st.subheader("Suggested Internet Providers")# Get Suggestions Buttonif st.sidebar.button("Get Suggestions"): if location: providers = fetch_providers(location) st.markdown("### Satellite Providers") for provider in providers["satellite"]: st.write(f"- **{provider['name']}** ({provider['type']}): {provider['cost']} | Coverage: {provider['coverage']}") st.markdown("### Local Providers") for provider in providers["local"]: st.write(f"- **{provider['name']}** ({provider['type']}): {provider['cost']} | Coverage: {provider['coverage']}") st.subheader(f"Suggestions for {needs}") suggestions = fetch_tavily_suggestions(location, needs) st.write(suggestions) else: st.warning("Please enter your location to see provider recommendations.")
# Signal Boosting Tipselif needs == "Signal Boosting Tips": st.subheader("Signal Boosting Tips") st.markdown(""" - **Place your router** in a central location, away from walls and obstructions. - Use **Wi-Fi range extenders** or mesh networks to improve coverage. - Install external antennas for better signal reception. - Minimize interference by keeping the router away from electronic devices like microwaves. """)
# Offline Tools Recommendationselif needs == "Offline Tools": st.subheader("Recommended Offline Tools") st.markdown(""" - **Education**: Download content from [Khan Academy](https://www.khanacademy.org/) or use offline features of apps like Coursera. - **Healthcare**: Use offline-first telemedicine tools like Healthline's symptom checker. - **Agriculture**: Use apps like FarmLogs for crop monitoring (syncs data when online). - **Business**: Set up Point-of-Sale (POS) systems like Square, which work offline and sync when connected. """)
# Footerst.markdown("---")st.caption("Developed with ❤️ using open-source tools for rural communities.")
st.warning("Please enter your location to get recommendations.")app.py+36-58