SHAMIL SHAHBAZ AWAN commited on
Commit
14210ca
·
verified ·
1 Parent(s): 2c5039a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -110
app.py CHANGED
@@ -11,16 +11,12 @@ if GROQ_API_KEY is None:
11
  else:
12
  groq_client = Groq(api_key=GROQ_API_KEY)
13
 
14
- # Step 3: Enhance with Groq
15
  def enhance_with_groq(query):
16
- """
17
- Enhance the suggestions using Groq.
18
- """
19
  try:
20
- # Perform chat completion using Groq
21
  chat_completion = groq_client.chat.completions.create(
22
  messages=[{"role": "user", "content": query}],
23
- model="llama-3.3-70b-versatile", # Specify model for Groq
24
  )
25
  return chat_completion.choices[0].message.content
26
  except Exception as e:
@@ -34,7 +30,7 @@ else:
34
  - Affordable internet solutions.
35
  - Signal boosting tips.
36
  - Offline tools for education, healthcare, and business.
37
- - More!
38
  """)
39
 
40
  # Sidebar User Inputs
@@ -46,120 +42,51 @@ else:
46
  "Offline Tools",
47
  "Types of Internet Connections",
48
  "Educational Resources",
49
- "Energy-Efficient Connectivity Solutions"
 
50
  ])
51
 
52
  # Fetch and Enhance Suggestions
53
- if st.sidebar.button("Get Suggestions"):
54
  if location:
55
- # Formulate the query for Groq based on user inputs
56
  query = f"Provide suggestions for {needs} in {location}, especially affordable options and tips."
57
-
58
  st.subheader(f"Suggestions for {needs} in {location}")
59
-
60
- # Get response from Groq
61
  groq_response = enhance_with_groq(query)
62
-
63
- # Display Groq response
64
  st.write("Suggestions from Groq:")
65
  st.write(groq_response)
66
  else:
67
  st.warning("Please enter your location to get recommendations.")
68
 
69
- # New Features
70
-
71
- # Types of Internet Connections
72
- def types_of_internet_connections():
73
- st.subheader("Types of Internet Connections")
74
- st.markdown("""
75
- In rural areas, you may encounter various types of internet connections. Each has its pros and cons, depending on your needs:
76
-
77
- - **Satellite Internet**:
78
- - Good for remote areas where no other connectivity is available.
79
- - Pros: Available almost everywhere.
80
- - Cons: Can be expensive and has higher latency.
81
-
82
- - **4G/5G LTE**:
83
- - Increasingly popular in rural areas.
84
- - Pros: Affordable, high-speed internet.
85
- - Cons: Coverage may be limited in remote regions.
86
-
87
- - **Fiber Optic**:
88
- - The fastest connection type.
89
- - Pros: Very fast speeds (up to 1 Gbps).
90
- - Cons: Limited availability in rural areas.
91
-
92
- - **DSL (Digital Subscriber Line)**:
93
- - Common in many rural areas.
94
- - Pros: Reliable, affordable.
95
- - Cons: Slower speeds compared to fiber or LTE.
96
-
97
- - **Fixed Wireless**:
98
- - Uses radio signals to provide internet access.
99
- - Pros: Available in remote areas, affordable.
100
- - Cons: Speeds vary based on distance from the tower.
101
-
102
- - **Dial-Up**:
103
- - Rarely used nowadays, but still present in some rural areas.
104
- - Pros: Available anywhere a phone line exists.
105
- - Cons: Very slow speeds, high latency.
106
- """)
107
-
108
- # Educational Resources
109
- def educational_resources():
110
- st.subheader("Educational Resources on Internet Connectivity")
111
- st.markdown("""
112
- Here are some useful educational resources to help you understand how internet connectivity works and how it can be improved in rural areas:
113
-
114
- - **Internet Basics**:
115
- - [How the Internet Works](https://www.explainthatstuff.com/how-the-internet-works.html) – A simple guide to understanding the basics of internet technology.
116
-
117
- - **Improving Rural Connectivity**:
118
- - [The State of Rural Broadband](https://www.broadbandnow.com/research/state-of-broadband) – Research on rural broadband and how to improve it.
119
-
120
- - **Satellite Internet**:
121
- - [Satellites for Internet](https://www.explainingthecloud.com/satellite-internet/) – A guide to how satellite internet works.
122
-
123
- - **Wi-Fi Technology**:
124
- - [How Wi-Fi Works](https://www.wi-fi.org/discover-wi-fi) – Learn about the technology behind Wi-Fi and how it can be optimized.
125
-
126
- - **Internet Safety**:
127
- - [Staying Safe Online](https://www.getsafeonline.org/) – A comprehensive resource for understanding internet safety, especially in rural communities where online security might be a concern.
128
- """)
129
-
130
- # Energy-Efficient Connectivity Solutions
131
- def energy_efficient_connectivity():
132
- st.subheader("Energy-Efficient Connectivity Solutions")
133
- st.markdown("""
134
- In rural areas, where power supply can be inconsistent, energy-efficient internet solutions are important. Here are a few options to consider:
135
-
136
- - **Solar-Powered Internet Solutions**:
137
- - Many rural areas are turning to solar-powered routers and internet infrastructure to provide a sustainable internet connection.
138
- - Pros: Green, cost-effective in the long run.
139
- - Cons: Initial setup costs, weather dependency.
140
-
141
- - **Energy-Efficient Modems and Routers**:
142
- - Choose modems and routers that are designed to consume less power, especially if you're running a small community network or a home-based system.
143
- - Look for Energy Star-certified devices.
144
-
145
- - **Low Power IoT Devices**:
146
- - For rural communities that rely on low-cost, low-power internet, Internet of Things (IoT) devices can be energy-efficient.
147
- - Use IoT to monitor remote areas, for smart agriculture, and more.
148
-
149
- - **Energy-Efficient Data Centers**:
150
- - If you are running a local data center in rural areas, look for solutions that use renewable energy (wind, solar) to power your infrastructure.
151
-
152
- - **Smart Grid Technologies**:
153
- - Use smart grid technologies to balance energy usage while maintaining a reliable internet connection. These technologies are being adopted in rural areas to improve energy distribution and reduce energy consumption.
154
- """)
155
-
156
- # Display Additional Features
157
- if needs == "Types of Internet Connections":
158
- types_of_internet_connections()
159
- elif needs == "Educational Resources":
160
- educational_resources()
161
- elif needs == "Energy-Efficient Connectivity Solutions":
162
- energy_efficient_connectivity()
163
 
164
  # Optional Query Box for Additional Questions
165
  st.sidebar.header("Have Another Query?")
@@ -167,7 +94,6 @@ else:
167
 
168
  if user_query:
169
  st.subheader(f"Your Query: {user_query}")
170
- # Get response from Groq for the additional user query
171
  query_response = enhance_with_groq(user_query)
172
  st.write("Response from Groq:")
173
  st.write(query_response)
 
11
  else:
12
  groq_client = Groq(api_key=GROQ_API_KEY)
13
 
14
+ # Step 3: Function to interact with Groq
15
  def enhance_with_groq(query):
 
 
 
16
  try:
 
17
  chat_completion = groq_client.chat.completions.create(
18
  messages=[{"role": "user", "content": query}],
19
+ model="llama-3.3-70b-versatile",
20
  )
21
  return chat_completion.choices[0].message.content
22
  except Exception as e:
 
30
  - Affordable internet solutions.
31
  - Signal boosting tips.
32
  - Offline tools for education, healthcare, and business.
33
+ - Connectivity recommendations tailored to your needs.
34
  """)
35
 
36
  # Sidebar User Inputs
 
42
  "Offline Tools",
43
  "Types of Internet Connections",
44
  "Educational Resources",
45
+ "Energy-Efficient Connectivity Solutions",
46
+ "Recommend Connectivity System"
47
  ])
48
 
49
  # Fetch and Enhance Suggestions
50
+ if needs != "Recommend Connectivity System" and st.sidebar.button("Get Suggestions"):
51
  if location:
 
52
  query = f"Provide suggestions for {needs} in {location}, especially affordable options and tips."
 
53
  st.subheader(f"Suggestions for {needs} in {location}")
 
 
54
  groq_response = enhance_with_groq(query)
 
 
55
  st.write("Suggestions from Groq:")
56
  st.write(groq_response)
57
  else:
58
  st.warning("Please enter your location to get recommendations.")
59
 
60
+ # "Recommend Connectivity System" Option
61
+ if needs == "Recommend Connectivity System":
62
+ st.subheader("Recommend Connectivity System")
63
+ st.markdown("Provide the following details to get a personalized recommendation for your connectivity system:")
64
+
65
+ # Inputs from the user
66
+ user_budget = st.number_input("Enter your budget (in USD):", min_value=10, step=10)
67
+ num_users = st.number_input("Number of users:", min_value=1, step=1)
68
+ connection_preference = st.selectbox("Preferred Connection Type:", [
69
+ "Satellite Internet",
70
+ "4G/5G LTE",
71
+ "Fiber Optic",
72
+ "DSL",
73
+ "Fixed Wireless",
74
+ "No Preference"
75
+ ])
76
+
77
+ # Get recommendation on button click
78
+ if st.button("Get Recommendation"):
79
+ if user_budget and num_users:
80
+ recommendation_query = (
81
+ f"Recommend a suitable connectivity system for a rural area. "
82
+ f"Budget: ${user_budget}, Number of Users: {num_users}, "
83
+ f"Connection Preference: {connection_preference}."
84
+ )
85
+ recommendation_response = enhance_with_groq(recommendation_query)
86
+ st.subheader("Recommended Connectivity System")
87
+ st.write(recommendation_response)
88
+ else:
89
+ st.warning("Please fill in all required fields.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
  # Optional Query Box for Additional Questions
92
  st.sidebar.header("Have Another Query?")
 
94
 
95
  if user_query:
96
  st.subheader(f"Your Query: {user_query}")
 
97
  query_response = enhance_with_groq(user_query)
98
  st.write("Response from Groq:")
99
  st.write(query_response)