|
|
import streamlit as st |
|
|
from groq import Groq |
|
|
import os |
|
|
|
|
|
|
|
|
GROQ_API_KEY = st.secrets["GROQ_API_KEY"] |
|
|
|
|
|
|
|
|
if GROQ_API_KEY is None: |
|
|
st.error("Groq API key is missing. Please add the API key in Hugging Face Secrets.") |
|
|
else: |
|
|
groq_client = Groq(api_key=GROQ_API_KEY) |
|
|
|
|
|
|
|
|
def enhance_with_groq(query): |
|
|
try: |
|
|
chat_completion = groq_client.chat.completions.create( |
|
|
messages=[{"role": "user", "content": query}], |
|
|
model="llama-3.3-70b-versatile", |
|
|
) |
|
|
return chat_completion.choices[0].message.content |
|
|
except Exception as e: |
|
|
return f"Error with Groq API: {str(e)}" |
|
|
|
|
|
|
|
|
st.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. |
|
|
- Connectivity recommendations tailored to your needs. |
|
|
""") |
|
|
|
|
|
|
|
|
st.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", |
|
|
"Types of Internet Connections", |
|
|
"Educational Resources", |
|
|
"Energy-Efficient Connectivity Solutions", |
|
|
"Recommend Connectivity System" |
|
|
]) |
|
|
|
|
|
|
|
|
if needs != "Recommend Connectivity System" and st.sidebar.button("Get Suggestions"): |
|
|
if location: |
|
|
query = f"Provide suggestions for {needs} in {location}, especially affordable options and tips." |
|
|
st.subheader(f"Suggestions for {needs} in {location}") |
|
|
groq_response = enhance_with_groq(query) |
|
|
st.write("Suggestions from Groq:") |
|
|
st.write(groq_response) |
|
|
else: |
|
|
st.warning("Please enter your location to get recommendations.") |
|
|
|
|
|
|
|
|
if needs == "Recommend Connectivity System": |
|
|
st.subheader("Recommend Connectivity System") |
|
|
st.markdown("Provide the following details to get a personalized recommendation for your connectivity system:") |
|
|
|
|
|
|
|
|
user_budget = st.number_input("Enter your budget (in USD):", min_value=10, step=10) |
|
|
num_users = st.number_input("Number of users:", min_value=1, step=1) |
|
|
connection_preference = st.selectbox("Preferred Connection Type:", [ |
|
|
"Satellite Internet", |
|
|
"4G/5G LTE", |
|
|
"Fiber Optic", |
|
|
"DSL", |
|
|
"Fixed Wireless", |
|
|
"No Preference" |
|
|
]) |
|
|
|
|
|
|
|
|
if st.button("Get Recommendation"): |
|
|
if user_budget and num_users: |
|
|
recommendation_query = ( |
|
|
f"Recommend a suitable connectivity system for a rural area. " |
|
|
f"Budget: ${user_budget}, Number of Users: {num_users}, " |
|
|
f"Connection Preference: {connection_preference}." |
|
|
) |
|
|
recommendation_response = enhance_with_groq(recommendation_query) |
|
|
st.subheader("Recommended Connectivity System") |
|
|
st.write(recommendation_response) |
|
|
else: |
|
|
st.warning("Please fill in all required fields.") |
|
|
|
|
|
|
|
|
st.sidebar.header("Have Another Query?") |
|
|
user_query = st.sidebar.text_input("Ask a Question (Optional)", "") |
|
|
|
|
|
if user_query: |
|
|
st.subheader(f"Your Query: {user_query}") |
|
|
query_response = enhance_with_groq(user_query) |
|
|
st.write("Response from Groq:") |
|
|
st.write(query_response) |
|
|
|