File size: 5,256 Bytes
ef552d9 67048bb 936114c ef552d9 9a762b6 67048bb 936114c d7b372a f1778c0 67048bb ef552d9 14210ca 9a762b6 67048bb 9a762b6 14210ca 67048bb 2d62fca d7b372a 2d62fca cb9ebed 2d62fca 8569823 f1778c0 ce500c4 f1778c0 b1b5a3f 14210ca b1b5a3f f1778c0 67048bb 14210ca f1778c0 9a762b6 f1778c0 9a762b6 f1778c0 b1b5a3f 14210ca 2c5039a b1b5a3f 2c5039a cb9ebed 84e7946 cb9ebed 84e7946 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
import streamlit as st
from groq import Groq
import os
# Step 1: Retrieve API Key from Hugging Face Secrets
GROQ_API_KEY = st.secrets["GROQ_API_KEY"]
# Step 2: Initialize Groq Client
if GROQ_API_KEY is None:
st.error("Groq API key is missing. Please add the API key in Secrets.")
else:
groq_client = Groq(api_key=GROQ_API_KEY)
# Step 3: Function to interact with Groq
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)}"
# Step 4: Add Background Image using Custom CSS
background_image_url = "https://static.vecteezy.com/ti/fotos-gratis/t1/21196013-futurista-tecnologia-fundo-azul-linha-onda-luz-tela-abstrato-ilustracao-foto.jpg"
st.markdown(
f"""
<style>
.stApp {{
background-image: url("{background_image_url}");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}}
.stApp * {{
color: white !important;
text-shadow: 1px 1px 2px black;
}}
</style>
""",
unsafe_allow_html=True
)
# Step 5: Build Streamlit UI
st.title("π NetBridge: Bridging Connectivity Gaps π")
st.markdown("""
Welcome to **NetBridge**!
This app helps you with:
- Finding affordable internet solutions tailored to your location and needs.
- Tips for boosting your internet signal in remote areas.
- Offline tools for education, healthcare, and business continuity.
- Recommendations for connectivity systems based on your inputs.
- Addressing custom queries to assist with connectivity challenges.
""")
# Sidebar User Inputs
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"
])
# Fetch and Enhance Suggestions
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.")
# "Recommend Connectivity System" Option
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:")
# Inputs from the user
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"
])
# Get recommendation on button click
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.")
# Optional Query Box for Additional Questions
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)
# Add a bottom-left corner credit
st.markdown("""
<style>
.bottom-left {
position: fixed;
bottom: 0;
left: 0;
padding: 10px;
font-size: 14px;
font-family: 'Arial', sans-serif;
color: white;
background-color: rgba(0, 0, 0, 0.5);
border-top-right-radius: 8px;
}
</style>
<div class="bottom-left">
Created by Team Materio π
</div>
""", unsafe_allow_html=True)
|