-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.py
133 lines (81 loc) · 4.59 KB
/
search.py
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
import streamlit as st
import pandas as pd
import base64
from googletrans import Translator
def run():
translator = Translator()
def get_base64_of_bin_file(bin_file):
with open(bin_file, 'rb') as f:
data = f.read()
return base64.b64encode(data).decode()
gif_path = "back6.gif"
base64_gif = get_base64_of_bin_file(gif_path)
page_bg = f"""
<style>
[data-testid="stAppViewContainer"] {{
background-image: url("data:image/gif;base64,{base64_gif}");
background-size: cover;
background-position: center;
}}
.black-text {{
color: black;
margin-left: 480px;
}}
.custom-heading {{
color: black;
margin-left: 480px;
font-size: 35px;
}}
</style>
"""
st.markdown(page_bg, unsafe_allow_html=True)
def translate_text(text, dest_language):
language_codes = {
'English': 'en',
'Hindi': 'hi',
'Gujarati': 'gu',
'Marathi': 'mr'
}
return translator.translate(text, dest=language_codes[dest_language]).text
def translate_page(elements, target_language):
translated_elements = [translate_text(element, target_language) for element in elements]
return translated_elements
def load_image(image_file):
img = open(image_file, 'rb').read()
return img
@st.cache_data
def load_data():
df = pd.read_excel('wateer.xlsx')
return df
df = load_data()
##st.sidebar.title("Navigation")
language = st.sidebar.selectbox(
'Select Language',
('English', 'Hindi', 'Gujarati', 'Marathi')
)
sidebar_titles = ["Go to", "Home", "About", "Calculate Water Footprint", "Know Your Daily Footprint"]
translated_sidebar = translate_page(sidebar_titles, language)
option = st.sidebar.radio(translated_sidebar[0], [translated_sidebar[1], translated_sidebar[2], translated_sidebar[3], translated_sidebar[4]], index=2)
if option == translated_sidebar[1]:
st.markdown(f'<h1 style="color: black; margin-left: 20px;">{translate_text("Welcome to the Landing Page", language)}</h1>', unsafe_allow_html=True)
st.markdown(f'<p style="color: black; margin-left: 20px;">{translate_text("Welcome to our homepage where you can learn more about our app and features!", language)}</p>', unsafe_allow_html=True)
elif option == translated_sidebar[2]:
st.header(translate_text("About Us", language))
st.markdown(f"## {translate_text('About', language)}")
st.write(translate_text("This application helps you calculate something special. Learn more about our mission and services.", language))
elif option == translated_sidebar[3]:
st.header(translate_text("Water Footprint Calculator", language))
sub_option = st.sidebar.radio(translate_text("Choose an option:", language), [translate_text("Search", language), translate_text("Scan", language)], index=0)
if sub_option == translate_text("Search", language):
item = st.selectbox(translate_text("Select an item:", language), df['Item'].unique())
quantity = st.number_input(translate_text("Enter quantity (in kg):", language), min_value=0, value=1)
if st.button(translate_text("Calculate Water Footprint", language)):
item_waterfootprint = df[df['Item'] == item]['WaterFootprint'].values[0]
total_waterfootprint = item_waterfootprint * quantity
st.write(f"{translate_text('The total water footprint for', language)} {quantity} kg {translate_text('of', language)} {item} {translate_text('is', language)} {total_waterfootprint:.2f}, {translate_text('bottles of water', language)}.")
st.image(load_image("wb.jpg"), caption=translate_text("Water Footprint", language), use_column_width=False, width=300)
elif sub_option == translate_text("Scan", language):
st.write(translate_text("Scan functionality is currently under development. Please check back later.", language))
elif option == translated_sidebar[4]:
st.header(translate_text("Know Your Daily Footprint", language))
st.write(translate_text("You can enter the data for your daily activities and calculate your daily water footprint.", language))