SHAMIL SHAHBAZ AWAN
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,42 @@
|
|
| 1 |
-
import requests
|
| 2 |
import streamlit as st
|
| 3 |
-
|
| 4 |
-
TAVILY_API_KEY= st.secrets["TAVILY_API_KEY"]
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
def fetch_tavily_suggestions(location, need):
|
| 9 |
"""
|
| 10 |
Use Tavily API to fetch real-time suggestions based on location and need.
|
| 11 |
"""
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
response = requests.post(api_url, headers=headers, json=payload)
|
| 19 |
-
if response.status_code == 200:
|
| 20 |
-
return response.json().get("text", "No recommendations available.")
|
| 21 |
-
else:
|
| 22 |
-
return f"Error: Unable to fetch data from Tavily API. Status code: {response.status_code}"
|
| 23 |
-
|
| 24 |
-
# Streamlit App
|
| 25 |
st.title("Rural Connectivity Advisor")
|
| 26 |
st.markdown("""
|
| 27 |
-
Welcome to the **Rural Connectivity Advisor**!
|
|
|
|
| 28 |
- Affordable internet solutions.
|
| 29 |
- Signal boosting tips.
|
| 30 |
- Offline tools for education, healthcare, and business.
|
| 31 |
""")
|
| 32 |
|
| 33 |
-
# User Inputs
|
| 34 |
st.sidebar.header("Input Your Details")
|
| 35 |
location = st.sidebar.text_input("Enter Your Location (e.g., City, District)")
|
| 36 |
needs = st.sidebar.selectbox("What do you need?", ["Internet Provider", "Signal Boosting Tips", "Offline Tools"])
|
| 37 |
|
| 38 |
-
#
|
| 39 |
if st.sidebar.button("Get Suggestions"):
|
| 40 |
if location:
|
| 41 |
-
st.subheader(f"Suggestions for {needs}")
|
| 42 |
suggestions = fetch_tavily_suggestions(location, needs)
|
| 43 |
st.write(suggestions)
|
| 44 |
else:
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from tavily import TavilyClient
|
|
|
|
| 3 |
|
| 4 |
+
# Step 1: Initialize Tavily Client with API key from Streamlit secrets
|
| 5 |
+
TAVILY_API_KEY = st.secrets["TAVILY_API_KEY"] # Retrieve API key securely from secrets
|
| 6 |
+
tavily_client = TavilyClient(api_key=TAVILY_API_KEY)
|
| 7 |
|
| 8 |
+
# Step 2: Fetch Suggestions Using Tavily
|
| 9 |
def fetch_tavily_suggestions(location, need):
|
| 10 |
"""
|
| 11 |
Use Tavily API to fetch real-time suggestions based on location and need.
|
| 12 |
"""
|
| 13 |
+
query = f"Provide {need.lower()} recommendations for rural areas near {location}. Focus on affordability and accessibility."
|
| 14 |
+
try:
|
| 15 |
+
# Execute the query using TavilyClient
|
| 16 |
+
response = tavily_client.search(query)
|
| 17 |
+
return response.get("text", "No recommendations available.") # Extract the 'text' response
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"Error: {str(e)}"
|
| 20 |
|
| 21 |
+
# Step 3: Build Streamlit UI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
st.title("Rural Connectivity Advisor")
|
| 23 |
st.markdown("""
|
| 24 |
+
Welcome to the **Rural Connectivity Advisor**!
|
| 25 |
+
This app helps rural communities find:
|
| 26 |
- Affordable internet solutions.
|
| 27 |
- Signal boosting tips.
|
| 28 |
- Offline tools for education, healthcare, and business.
|
| 29 |
""")
|
| 30 |
|
| 31 |
+
# Sidebar User Inputs
|
| 32 |
st.sidebar.header("Input Your Details")
|
| 33 |
location = st.sidebar.text_input("Enter Your Location (e.g., City, District)")
|
| 34 |
needs = st.sidebar.selectbox("What do you need?", ["Internet Provider", "Signal Boosting Tips", "Offline Tools"])
|
| 35 |
|
| 36 |
+
# Fetch and Display Suggestions
|
| 37 |
if st.sidebar.button("Get Suggestions"):
|
| 38 |
if location:
|
| 39 |
+
st.subheader(f"Suggestions for {needs} in {location}")
|
| 40 |
suggestions = fetch_tavily_suggestions(location, needs)
|
| 41 |
st.write(suggestions)
|
| 42 |
else:
|