SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243import streamlit as stfrom tavily import TavilyClient# Step 1: Initialize Tavily Client with API key from Streamlit secretsTAVILY_API_KEY = st.secrets["TAVILY_API_KEY"] # Retrieve API key securely from secretstavily_client = TavilyClient(api_key=TAVILY_API_KEY)# Step 2: Fetch Suggestions Using Tavilydef fetch_tavily_suggestions(location, need):"""Use Tavily API to fetch real-time suggestions based on location and need."""query = f"Provide {need.lower()} recommendations for rural areas near {location}. Focus on affordability and accessibility."try:# Execute the query using TavilyClientresponse = tavily_client.search(query)return response.get("text", "No recommendations available.") # Extract the 'text' responseexcept Exception as e:return f"Error: {str(e)}"# Step 3: Build Streamlit UIst.title("Rural Connectivity Advisor")st.markdown("""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 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"])# Fetch and Display Suggestionsif st.sidebar.button("Get Suggestions"):if location:st.subheader(f"Suggestions for {needs} in {location}")suggestions = fetch_tavily_suggestions(location, needs)st.write(suggestions)else:st.warning("Please enter your location to get recommendations.")12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import streamlit as stfrom tavily import TavilyClient# Step 1: Retrieve Tavily API Key from Hugging Face SecretsTAVILY_API_KEY = st.secrets["TAVILY_API_KEY"] # Access the API key securely from Hugging Face Secretsif TAVILY_API_KEY is None:st.error("API key is missing. Please add the TAVILY_API_KEY in Hugging Face Secrets.")else:# Initialize Tavily Client with the API keytavily_client = TavilyClient(api_key=TAVILY_API_KEY)# Step 2: Fetch Suggestions Using Tavilydef fetch_tavily_suggestions(location, need):"""Use Tavily API to fetch real-time suggestions based on location and need."""query = f"Provide affordable internet providers or satellite internet services for rural areas near {location}, especially for low-income families."try:# Execute the query using TavilyClientresponse = tavily_client.search(query)st.write(f"Raw API Response: {response}") # Debug: print the raw response for inspection# Check if the 'text' key exists in the response and return itif "text" in response:return response["text"]else:return "No suggestions available in the response."except Exception as e:return f"Error: {str(e)}"# Step 3: Build Streamlit UIst.title("Rural Connectivity Advisor")st.markdown("""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 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"])# Fetch and Display Suggestionsif st.sidebar.button("Get Suggestions"):if location:st.subheader(f"Suggestions for {needs} in {location}")suggestions = fetch_tavily_suggestions(location, needs)st.write(suggestions)else:st.warning("Please enter your location to get recommendations.")
app.py+48-36