SHAMIL SHAHBAZ AWAN
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,70 +1,48 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
st.title("Rural Connectivity Advisor")
|
| 7 |
st.markdown("""
|
| 8 |
-
Welcome to the **Rural Connectivity Advisor**! This app helps rural communities find
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
""")
|
| 11 |
|
| 12 |
-
#
|
| 13 |
st.sidebar.header("Input Your Details")
|
| 14 |
location = st.sidebar.text_input("Enter Your Location (e.g., City, District)")
|
| 15 |
needs = st.sidebar.selectbox("What do you need?", ["Internet Provider", "Signal Boosting Tips", "Offline Tools"])
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
def fetch_providers(location):
|
| 20 |
-
"""Fetch a list of internet providers based on location (simulated data)."""
|
| 21 |
-
# Simulated data (replace with a real API or database in the future)
|
| 22 |
-
providers = {
|
| 23 |
-
"satellite": [
|
| 24 |
-
{"name": "Starlink", "type": "Satellite", "cost": "$110/month", "coverage": "Global"},
|
| 25 |
-
{"name": "HughesNet", "type": "Satellite", "cost": "$60/month", "coverage": "North America"},
|
| 26 |
-
],
|
| 27 |
-
"local": [
|
| 28 |
-
{"name": "LocalNet Rural", "type": "Local ISP", "cost": "$40/month", "coverage": "Regional"},
|
| 29 |
-
],
|
| 30 |
-
}
|
| 31 |
-
return providers
|
| 32 |
-
|
| 33 |
-
# Display Internet Providers
|
| 34 |
-
if needs == "Internet Provider":
|
| 35 |
-
st.subheader("Suggested Internet Providers")
|
| 36 |
if location:
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
st.write(f"- **{provider['name']}** ({provider['type']}): {provider['cost']} | Coverage: {provider['coverage']}")
|
| 41 |
-
st.markdown("### Local Providers")
|
| 42 |
-
for provider in providers["local"]:
|
| 43 |
-
st.write(f"- **{provider['name']}** ({provider['type']}): {provider['cost']} | Coverage: {provider['coverage']}")
|
| 44 |
else:
|
| 45 |
-
st.warning("Please enter your location to
|
| 46 |
-
|
| 47 |
-
# Signal Boosting Tips
|
| 48 |
-
elif needs == "Signal Boosting Tips":
|
| 49 |
-
st.subheader("Signal Boosting Tips")
|
| 50 |
-
st.markdown("""
|
| 51 |
-
- **Place your router** in a central location, away from walls and obstructions.
|
| 52 |
-
- Use **Wi-Fi range extenders** or mesh networks to improve coverage.
|
| 53 |
-
- Install external antennas for better signal reception.
|
| 54 |
-
- Minimize interference by keeping the router away from electronic devices like microwaves.
|
| 55 |
-
""")
|
| 56 |
-
|
| 57 |
-
# Offline Tools Recommendations
|
| 58 |
-
elif needs == "Offline Tools":
|
| 59 |
-
st.subheader("Recommended Offline Tools")
|
| 60 |
-
st.markdown("""
|
| 61 |
-
- **Education**: Download content from [Khan Academy](https://www.khanacademy.org/) or use offline features of apps like Coursera.
|
| 62 |
-
- **Healthcare**: Use offline-first telemedicine tools like Healthline's symptom checker.
|
| 63 |
-
- **Agriculture**: Use apps like FarmLogs for crop monitoring (syncs data when online).
|
| 64 |
-
- **Business**: Set up Point-of-Sale (POS) systems like Square, which work offline and sync when connected.
|
| 65 |
-
""")
|
| 66 |
-
|
| 67 |
-
# Footer
|
| 68 |
-
st.markdown("---")
|
| 69 |
-
st.caption("Developed with ❤️ using open-source tools for rural communities.")
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import os
|
| 4 |
+
# Tavily API Key
|
| 5 |
+
client = Groq(
|
| 6 |
+
api_key=os.environ.get("TAVILY_API_KEY"),
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# Function to fetch suggestions from Tavily API
|
| 11 |
+
def fetch_tavily_suggestions(location, need):
|
| 12 |
+
"""
|
| 13 |
+
Use Tavily API to fetch real-time suggestions based on location and need.
|
| 14 |
+
"""
|
| 15 |
+
headers = {"Authorization": f"Bearer {TAVILY_API_KEY}"}
|
| 16 |
+
prompt = f"Provide {need.lower()} recommendations for rural areas near {location}. Focus on affordability and accessibility."
|
| 17 |
+
api_url = "https://api.tavily.ai/v1/generate"
|
| 18 |
+
|
| 19 |
+
payload = {"prompt": prompt, "model": "your-model-choice", "max_tokens": 300}
|
| 20 |
+
|
| 21 |
+
response = requests.post(api_url, headers=headers, json=payload)
|
| 22 |
+
if response.status_code == 200:
|
| 23 |
+
return response.json().get("text", "No recommendations available.")
|
| 24 |
+
else:
|
| 25 |
+
return f"Error: Unable to fetch data from Tavily API. Status code: {response.status_code}"
|
| 26 |
|
| 27 |
+
# Streamlit App
|
| 28 |
st.title("Rural Connectivity Advisor")
|
| 29 |
st.markdown("""
|
| 30 |
+
Welcome to the **Rural Connectivity Advisor**! This app helps rural communities find:
|
| 31 |
+
- Affordable internet solutions.
|
| 32 |
+
- Signal boosting tips.
|
| 33 |
+
- Offline tools for education, healthcare, and business.
|
| 34 |
""")
|
| 35 |
|
| 36 |
+
# User Inputs
|
| 37 |
st.sidebar.header("Input Your Details")
|
| 38 |
location = st.sidebar.text_input("Enter Your Location (e.g., City, District)")
|
| 39 |
needs = st.sidebar.selectbox("What do you need?", ["Internet Provider", "Signal Boosting Tips", "Offline Tools"])
|
| 40 |
|
| 41 |
+
# Get Suggestions Button
|
| 42 |
+
if st.sidebar.button("Get Suggestions"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
if location:
|
| 44 |
+
st.subheader(f"Suggestions for {needs}")
|
| 45 |
+
suggestions = fetch_tavily_suggestions(location, needs)
|
| 46 |
+
st.write(suggestions)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
else:
|
| 48 |
+
st.warning("Please enter your location to get recommendations.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|