Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import time
|
|
5 |
import plotly.express as px
|
6 |
from groq import Groq
|
7 |
from dotenv import load_dotenv
|
|
|
8 |
|
9 |
# Load environment variables
|
10 |
load_dotenv()
|
@@ -107,8 +108,8 @@ st.markdown("""
|
|
107 |
.country-btn {
|
108 |
display: flex;
|
109 |
align-items: center;
|
110 |
-
justify-content:
|
111 |
-
gap:
|
112 |
width: 100%;
|
113 |
padding: 1.2rem;
|
114 |
border-radius: 15px;
|
@@ -120,6 +121,7 @@ st.markdown("""
|
|
120 |
border: 2px solid transparent;
|
121 |
font-weight: 600;
|
122 |
font-size: 1.1rem;
|
|
|
123 |
}
|
124 |
|
125 |
.country-btn:hover {
|
@@ -133,6 +135,12 @@ st.markdown("""
|
|
133 |
box-shadow: 0 8px 25px rgba(0,0,0,0.12);
|
134 |
}
|
135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
.footer {
|
137 |
text-align: center;
|
138 |
padding: 2.5rem;
|
@@ -202,6 +210,11 @@ st.markdown("""
|
|
202 |
.response-card {
|
203 |
padding: 1.8rem;
|
204 |
}
|
|
|
|
|
|
|
|
|
|
|
205 |
}
|
206 |
|
207 |
@media (max-width: 576px) {
|
@@ -229,6 +242,11 @@ st.markdown("""
|
|
229 |
.response-card {
|
230 |
padding: 1.5rem;
|
231 |
}
|
|
|
|
|
|
|
|
|
|
|
232 |
}
|
233 |
</style>
|
234 |
""", unsafe_allow_html=True)
|
@@ -236,7 +254,7 @@ st.markdown("""
|
|
236 |
# Country data with flags
|
237 |
COUNTRIES = {
|
238 |
"๐บ๐ธ United States": "US",
|
239 |
-
"๐ฌ๐ง United Kingdom": "
|
240 |
"๐จ๐ฆ Canada": "CA",
|
241 |
"๐ฆ๐บ Australia": "AU",
|
242 |
"๐ฎ๐ณ India": "IN",
|
@@ -276,11 +294,20 @@ MODELS = {
|
|
276 |
"Mixtral-8x7b (Balanced)": "mixtral-8x7b-32768"
|
277 |
}
|
278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
# Function to get rights information from Groq API
|
280 |
def get_legal_rights(country, scenario, model_name):
|
281 |
"""Get legal rights information using Groq API"""
|
|
|
|
|
282 |
system_prompt = f"""
|
283 |
-
You are an expert legal assistant specializing in {
|
284 |
Provide clear, accurate information about an individual's rights in the given scenario.
|
285 |
|
286 |
Guidelines:
|
@@ -297,9 +324,9 @@ def get_legal_rights(country, scenario, model_name):
|
|
297 |
|
298 |
user_prompt = f"""
|
299 |
Scenario: {scenario}
|
300 |
-
Country: {
|
301 |
|
302 |
-
Please provide a comprehensive list of rights for this situation in {
|
303 |
"""
|
304 |
|
305 |
try:
|
@@ -350,7 +377,7 @@ def main():
|
|
350 |
st.markdown("""
|
351 |
<div class="header">
|
352 |
<h1 style="margin:0;font-size:2.8rem;">Legal Rights Explorer Pro</h1>
|
353 |
-
<p style="margin:0;font-size:1.3rem;opacity:0.9;margin-top:12px;">Know
|
354 |
</div>
|
355 |
""", unsafe_allow_html=True)
|
356 |
|
@@ -393,9 +420,10 @@ def main():
|
|
393 |
for country_display in countries_col1:
|
394 |
is_selected = st.session_state.selected_country == country_display
|
395 |
btn_class = "country-btn selected" if is_selected else "country-btn"
|
|
|
396 |
|
397 |
if st.button(
|
398 |
-
|
399 |
key=f"btn_{country_display}",
|
400 |
use_container_width=True
|
401 |
):
|
@@ -408,9 +436,10 @@ def main():
|
|
408 |
for country_display in countries_col2:
|
409 |
is_selected = st.session_state.selected_country == country_display
|
410 |
btn_class = "country-btn selected" if is_selected else "country-btn"
|
|
|
411 |
|
412 |
if st.button(
|
413 |
-
|
414 |
key=f"btn_{country_display}",
|
415 |
use_container_width=True
|
416 |
):
|
@@ -424,7 +453,7 @@ def main():
|
|
424 |
awareness = [92, 89, 87, 85, 82, 88, 86, 84, 79, 81, 85, 83, 80, 78, 90, 85] # Simulated data
|
425 |
|
426 |
fig = px.bar(
|
427 |
-
x=countries,
|
428 |
y=awareness,
|
429 |
labels={'x': 'Country', 'y': 'Rights Awareness'},
|
430 |
color=awareness,
|
@@ -482,7 +511,7 @@ def main():
|
|
482 |
if st.session_state.selected_scenario:
|
483 |
country_code = COUNTRIES[st.session_state.selected_country]
|
484 |
|
485 |
-
with st.spinner(f"
|
486 |
response = get_legal_rights(
|
487 |
country_code,
|
488 |
st.session_state.selected_scenario,
|
|
|
5 |
import plotly.express as px
|
6 |
from groq import Groq
|
7 |
from dotenv import load_dotenv
|
8 |
+
import pycountry
|
9 |
|
10 |
# Load environment variables
|
11 |
load_dotenv()
|
|
|
108 |
.country-btn {
|
109 |
display: flex;
|
110 |
align-items: center;
|
111 |
+
justify-content: flex-start;
|
112 |
+
gap: 12px;
|
113 |
width: 100%;
|
114 |
padding: 1.2rem;
|
115 |
border-radius: 15px;
|
|
|
121 |
border: 2px solid transparent;
|
122 |
font-weight: 600;
|
123 |
font-size: 1.1rem;
|
124 |
+
text-align: left;
|
125 |
}
|
126 |
|
127 |
.country-btn:hover {
|
|
|
135 |
box-shadow: 0 8px 25px rgba(0,0,0,0.12);
|
136 |
}
|
137 |
|
138 |
+
.country-flag {
|
139 |
+
font-size: 1.8rem;
|
140 |
+
min-width: 40px;
|
141 |
+
text-align: center;
|
142 |
+
}
|
143 |
+
|
144 |
.footer {
|
145 |
text-align: center;
|
146 |
padding: 2.5rem;
|
|
|
210 |
.response-card {
|
211 |
padding: 1.8rem;
|
212 |
}
|
213 |
+
|
214 |
+
.country-flag {
|
215 |
+
font-size: 1.5rem;
|
216 |
+
min-width: 35px;
|
217 |
+
}
|
218 |
}
|
219 |
|
220 |
@media (max-width: 576px) {
|
|
|
242 |
.response-card {
|
243 |
padding: 1.5rem;
|
244 |
}
|
245 |
+
|
246 |
+
.country-flag {
|
247 |
+
font-size: 1.3rem;
|
248 |
+
min-width: 30px;
|
249 |
+
}
|
250 |
}
|
251 |
</style>
|
252 |
""", unsafe_allow_html=True)
|
|
|
254 |
# Country data with flags
|
255 |
COUNTRIES = {
|
256 |
"๐บ๐ธ United States": "US",
|
257 |
+
"๐ฌ๐ง United Kingdom": "GB",
|
258 |
"๐จ๐ฆ Canada": "CA",
|
259 |
"๐ฆ๐บ Australia": "AU",
|
260 |
"๐ฎ๐ณ India": "IN",
|
|
|
294 |
"Mixtral-8x7b (Balanced)": "mixtral-8x7b-32768"
|
295 |
}
|
296 |
|
297 |
+
# Function to get country name from code
|
298 |
+
def get_country_name(code):
|
299 |
+
try:
|
300 |
+
return pycountry.countries.get(alpha_2=code).name
|
301 |
+
except:
|
302 |
+
return code
|
303 |
+
|
304 |
# Function to get rights information from Groq API
|
305 |
def get_legal_rights(country, scenario, model_name):
|
306 |
"""Get legal rights information using Groq API"""
|
307 |
+
country_name = get_country_name(country)
|
308 |
+
|
309 |
system_prompt = f"""
|
310 |
+
You are an expert legal assistant specializing in {country_name} law.
|
311 |
Provide clear, accurate information about an individual's rights in the given scenario.
|
312 |
|
313 |
Guidelines:
|
|
|
324 |
|
325 |
user_prompt = f"""
|
326 |
Scenario: {scenario}
|
327 |
+
Country: {country_name}
|
328 |
|
329 |
+
Please provide a comprehensive list of rights for this situation in {country_name}.
|
330 |
"""
|
331 |
|
332 |
try:
|
|
|
377 |
st.markdown("""
|
378 |
<div class="header">
|
379 |
<h1 style="margin:0;font-size:2.8rem;">Legal Rights Explorer Pro</h1>
|
380 |
+
<p style="margin:0;font-size:1.3rem;opacity:0.9;margin-top:12px;">Know Your Rights, Anywhere. Anytime.</p>
|
381 |
</div>
|
382 |
""", unsafe_allow_html=True)
|
383 |
|
|
|
420 |
for country_display in countries_col1:
|
421 |
is_selected = st.session_state.selected_country == country_display
|
422 |
btn_class = "country-btn selected" if is_selected else "country-btn"
|
423 |
+
flag, name = country_display.split(" ", 1)
|
424 |
|
425 |
if st.button(
|
426 |
+
f'<div class="country-flag">{flag}</div> {name}',
|
427 |
key=f"btn_{country_display}",
|
428 |
use_container_width=True
|
429 |
):
|
|
|
436 |
for country_display in countries_col2:
|
437 |
is_selected = st.session_state.selected_country == country_display
|
438 |
btn_class = "country-btn selected" if is_selected else "country-btn"
|
439 |
+
flag, name = country_display.split(" ", 1)
|
440 |
|
441 |
if st.button(
|
442 |
+
f'<div class="country-flag">{flag}</div> {name}',
|
443 |
key=f"btn_{country_display}",
|
444 |
use_container_width=True
|
445 |
):
|
|
|
453 |
awareness = [92, 89, 87, 85, 82, 88, 86, 84, 79, 81, 85, 83, 80, 78, 90, 85] # Simulated data
|
454 |
|
455 |
fig = px.bar(
|
456 |
+
x=[get_country_name(code) for code in countries],
|
457 |
y=awareness,
|
458 |
labels={'x': 'Country', 'y': 'Rights Awareness'},
|
459 |
color=awareness,
|
|
|
511 |
if st.session_state.selected_scenario:
|
512 |
country_code = COUNTRIES[st.session_state.selected_country]
|
513 |
|
514 |
+
with st.spinner(f"๐ Analyzing your rights for '{st.session_state.selected_scenario}' in {st.session_state.selected_country}..."):
|
515 |
response = get_legal_rights(
|
516 |
country_code,
|
517 |
st.session_state.selected_scenario,
|