Srish117 commited on
Commit
ffb5a8f
·
verified ·
1 Parent(s): 975a839

Fixed an error

Browse files
Files changed (1) hide show
  1. app.py +88 -227
app.py CHANGED
@@ -1,227 +1,88 @@
1
- # import streamlit as st
2
- # import requests
3
-
4
- # # Your backend functions
5
- # def jina(url):
6
- # base_url = "https://r.jina.ai/"
7
- # url = base_url + url
8
- # response = requests.get(url)
9
- # return response.text
10
-
11
- # def price_cities(url):
12
- # text = jina(url)
13
- # pos1 = text.find('**')
14
- # new = text[:pos1]
15
-
16
- # twentytwok = new[int(new.find('22K')):int(new.find('24K'))]
17
- # value_22k = twentytwok[int(twentytwok.find('\n\n') + 1): int(twentytwok.find('\n\n+'))][3:]
18
-
19
- # twentyfourk = new[int(new.find('24K')):int(new.find('18K'))]
20
- # value_24k = twentyfourk[int(twentyfourk.find('\n\n') + 1): int(twentyfourk.find('\n\n+'))][3:]
21
-
22
- # eighteenk = new[int(new.find('18K')):]
23
- # value_18k = eighteenk[int(eighteenk.find('\n\n') + 1): int(eighteenk.find('\n\n+'))][3:]
24
-
25
- # return value_22k, value_24k, value_18k
26
-
27
- # # City list
28
- # cities = ['Ahmedabad', 'Ayodhya', 'Bangalore', 'Bhubaneswar', 'Chandigarh', 'Chennai',
29
- # 'Coimbatore', 'Delhi', 'Hyderabad', 'Jaipur', 'Kerala', 'Kolkata', 'Lucknow',
30
- # 'Madurai', 'Mangalore', 'Mumbai', 'Mysore', 'Nagpur', 'Nashik', 'Patna',
31
- # 'Pune', 'Rajkot', 'Salem', 'Surat', 'Trichy', 'Vadodara', 'Vijayawada', 'Visakhapatnam']
32
-
33
- # # Streamlit app
34
- # st.title('Gold Rates in Indian States')
35
-
36
- # # Dropdown for selecting the city
37
- # selected_city = st.selectbox('Select a City', cities)
38
-
39
- # # Fetch and display gold rates when a city is selected
40
- # if selected_city:
41
- # city_url = f"https://www.goodreturns.in/gold-rates/{selected_city}.html"
42
-
43
- # # Fetch the prices using your backend function
44
- # try:
45
- # x, y, z = price_cities(city_url)
46
- # st.write(f"Gold rates in {selected_city}:")
47
- # st.write(f"22K Gold: ₹{x}")
48
- # st.write(f"24K Gold: ₹{y}")
49
- # st.write(f"18K Gold: ₹{z}")
50
- # except:
51
- # st.error("Could not fetch the gold rates. Please try again.")
52
- # import streamlit as st
53
- # import requests
54
- # import pandas as pd
55
-
56
- # # Backend functions
57
- # def jina(url):
58
- # base_url = "https://r.jina.ai/"
59
- # url = base_url + url
60
- # response = requests.get(url)
61
- # return response.text
62
-
63
- # def price_cities(url):
64
- # text = jina(url)
65
- # pos1 = text.find('**')
66
- # new = text[:pos1]
67
-
68
- # twentytwok = new[int(new.find('22K')):int(new.find('24K'))]
69
- # value_22k = twentytwok[int(twentytwok.find('\n\n') + 1): int(twentytwok.find('\n\n+'))][3:]
70
-
71
- # twentyfourk = new[int(new.find('24K')):int(new.find('18K'))]
72
- # value_24k = twentyfourk[int(twentyfourk.find('\n\n') + 1): int(twentyfourk.find('\n\n+'))][3:]
73
-
74
- # eighteenk = new[int(new.find('18K')):]
75
- # value_18k = eighteenk[int(eighteenk.find('\n\n') + 1): int(eighteenk.find('\n\n+'))][3:]
76
-
77
- # return float(value_22k.replace(',', '')), float(value_24k.replace(',', '')), float(value_18k.replace(',', ''))
78
-
79
- # # City list
80
- # cities = ['Ahmedabad', 'Ayodhya', 'Bangalore', 'Bhubaneswar', 'Chandigarh', 'Chennai',
81
- # 'Coimbatore', 'Delhi', 'Hyderabad', 'Jaipur', 'Kerala', 'Kolkata', 'Lucknow',
82
- # 'Madurai', 'Mangalore', 'Mumbai', 'Mysore', 'Nagpur', 'Nashik', 'Patna',
83
- # 'Pune', 'Rajkot', 'Salem', 'Surat', 'Trichy', 'Vadodara', 'Vijayawada', 'Visakhapatnam']
84
-
85
- # # Streamlit UI
86
- # st.set_page_config(page_title="Gold Rates in Indian States", layout="wide")
87
-
88
- # # Sidebar with project and developer info
89
- # st.sidebar.title("Project Info")
90
- # st.sidebar.write("This project fetches current gold rates for 24K, 22K, and 18K gold from GoodReturns for 28 Indian states. The rates for 1g, 8g, and 10g are displayed.")
91
- # st.sidebar.write("**Developed by:**")
92
- # st.sidebar.write("[Srish Rachamalla](https://www.linkedin.com/in/srishrachamalla/)")
93
- # st.sidebar.write("[Sai Teja Pallerla](https://www.linkedin.com/in/saiteja-pallerla-668734225/)")
94
-
95
- # # Dropdown for selecting a city
96
- # st.title('Gold Rates in Indian States')
97
- # selected_city = st.selectbox('Select a City', cities)
98
-
99
- # Fetch and display gold rates when a city is selected
100
- # if selected_city:
101
- # city_url = f"https://www.goodreturns.in/gold-rates/{selected_city}.html"
102
-
103
- # try:
104
- # # Fetch the gold prices using your backend function
105
- # price_22k, price_24k, price_18k = price_cities(city_url)
106
-
107
- # # Prepare data for table
108
- # data = {
109
- # 'Karat': ['22K', '24K', '18K'],
110
- # '1g (₹)': [price_22k, price_24k, price_18k],
111
- # '8g (₹)': [price_22k * 8, price_24k * 8, price_18k * 8],
112
- # '10g (₹)': [price_22k * 10, price_24k * 10, price_18k * 10]
113
- # }
114
-
115
- # df = pd.DataFrame(data)
116
-
117
- # # Display the table in a styled format
118
- # st.write(f"### Gold rates in {selected_city}:")
119
- # st.table(df.style.format({'1g (₹)': '₹{:.2f}', '8g (₹)': '₹{:.2f}', '10g (₹)': '₹{:.2f}'}).background_gradient(cmap='YlOrRd'))
120
-
121
- # except Exception as e:
122
- # st.error(f"Could not fetch the gold rates. Please try again later.{e}")
123
- import streamlit as st
124
- import requests
125
- import pandas as pd
126
-
127
- # Your backend functions
128
- def jina(url):
129
- base_url = "https://r.jina.ai/"
130
- url = base_url + url
131
- response = requests.get(url)
132
- return response.text
133
-
134
- def price_cities(url):
135
- text = jina(url)
136
- pos1 = text.find('**')
137
- new = text[:pos1]
138
-
139
- twentytwok = new[int(new.find('22K')):int(new.find('24K'))]
140
- value_22k = twentytwok[int(twentytwok.find('\n\n') + 1): int(twentytwok.find('\n\n+'))][3:]
141
-
142
- twentyfourk = new[int(new.find('24K')):int(new.find('18K'))]
143
- value_24k = twentyfourk[int(twentyfourk.find('\n\n') + 1): int(twentyfourk.find('\n\n+'))][3:]
144
-
145
- eighteenk = new[int(new.find('18K')):]
146
- value_18k = eighteenk[int(eighteenk.find('\n\n') + 1): int(eighteenk.find('\n\n+'))][3:]
147
-
148
- return value_24k, value_22k, value_18k
149
-
150
- # List of cities
151
- cities = ['Ahmedabad', 'Ayodhya', 'Bangalore', 'Bhubaneswar', 'Chandigarh', 'Chennai',
152
- 'Coimbatore', 'Delhi', 'Hyderabad', 'Jaipur', 'Kerala', 'Kolkata', 'Lucknow',
153
- 'Madurai', 'Mangalore', 'Mumbai', 'Mysore', 'Nagpur', 'Nashik', 'Patna',
154
- 'Pune', 'Rajkot', 'Salem', 'Surat', 'Trichy', 'Vadodara', 'Vijayawada', 'Visakhapatnam']
155
-
156
- # Sidebar content
157
- st.sidebar.title("About the Project")
158
- # st.sidebar.write("This project, developed by [Srish Rachamalla](https://www.linkedin.com/in/srishrachamalla/) "
159
- # "and [Sai Teja Pallerla](https://www.linkedin.com/in/saiteja-pallerla-668734225/), "
160
- # "fetches and displays the latest gold rates for different cities in India. "
161
- # "You can view rates for 1g, 8g, and 10g for 22K, 24K, and 18K gold.")
162
-
163
- # st.sidebar.write("Use the dropdown to select a city and view the gold rates accordingly.")
164
- # Sidebar with project and developer info
165
- # st.sidebar.title("Project Info")
166
- st.sidebar.write("This project fetches current gold rates for 24K, 22K, and 18K gold from GoodReturns for 28 Indian states. The rates for 1g, 8g, and 10g are displayed.")
167
- st.sidebar.write("**Developed by:**")
168
- st.sidebar.write("[Srish Rachamalla](https://www.linkedin.com/in/srishrachamalla/)")
169
- st.sidebar.write("[Sai Teja Pallerla](https://www.linkedin.com/in/saiteja-pallerla-668734225/)")
170
-
171
- # Main UI
172
- st.title('Gold Rates in Indian Cities')
173
- st.subheader('Select a city to view the current gold rates')
174
-
175
- # Dropdown for city selection
176
- selected_city = st.selectbox('Select a City', cities)
177
-
178
- # Fetch and display gold rates
179
- if selected_city:
180
- city_url = f"https://www.goodreturns.in/gold-rates/{selected_city}.html"
181
-
182
- # Fetch the prices using your backend function
183
- try:
184
- value_24k, value_22k, value_18k = price_cities(city_url)
185
-
186
- # Convert string values to float for calculation
187
- value_22k = float(value_22k.replace(',', ''))
188
- value_24k = float(value_24k.replace(',', ''))
189
- value_18k = float(value_18k.replace(',', ''))
190
-
191
- # Prepare data for table
192
- data = {
193
- # 'SNO': [1, 2, 3],
194
- 'Gold Purity': ['24K', '22K', '18K'],
195
- '1g Price (₹)': [value_24k, value_22k, value_18k],
196
- '8g Price (₹)': [value_24k * 8, value_22k * 8, value_18k * 8],
197
- '10g Price (₹)': [value_24k * 10, value_22k * 10, value_18k * 10]
198
- }
199
-
200
- # Create a DataFrame for display
201
- df = pd.DataFrame(data,index=[1, 2, 3])
202
-
203
- # Display the DataFrame as a table
204
- st.write(f"Gold rates in {selected_city}:")
205
- st.dataframe(df.style.set_properties(**{
206
- 'background-color': 'black',
207
- 'color': 'white',
208
- 'border-color': 'ash'
209
- }))
210
-
211
- except:
212
- st.error("Could not fetch the gold rates. Please try again.")
213
- st.markdown("<br><hr><center><p style='color: grey;'>© 2024 All Rights Reserved</p></center><br>", unsafe_allow_html=True)
214
-
215
-
216
- # # Custom CSS to improve UI appearance
217
- # st.markdown("""
218
- # <style>
219
- # .stSidebar {
220
- # background-color: #f4f4f4;
221
- # }
222
- # .stApp {
223
- # background-color: #000000;
224
- # }
225
- # </style>
226
- # """, unsafe_allow_html=True)
227
-
 
1
+ import streamlit as st
2
+ import requests
3
+ import pandas as pd
4
+
5
+ # Your backend functions
6
+ def jina(url):
7
+ base_url = "https://r.jina.ai/"
8
+ url = base_url + url
9
+ response = requests.get(url)
10
+ return response.text
11
+
12
+ def price_cities(url):
13
+ text = jina(url)
14
+ pos1 = text.find('**')
15
+ new = text[:pos1]
16
+
17
+ twentytwok = new[int(new.find('22K')):int(new.find('24K'))]
18
+ value_22k = twentytwok[int(twentytwok.find('\n\n') + 1): int(twentytwok.find('\n\n+'))][3:]
19
+ value_22k = value_22k.split('\n')[0]
20
+
21
+ twentyfourk = new[int(new.find('24K')):int(new.find('18K'))]
22
+ value_24k = twentyfourk[int(twentyfourk.find('\n\n') + 1): int(twentyfourk.find('\n\n+'))][3:]
23
+ value_24k = value_24k.split('\n')[0]
24
+
25
+ eighteenk = new[int(new.find('18K')):]
26
+ value_18k = eighteenk[int(eighteenk.find('\n\n') + 1): int(eighteenk.find('\n\n+'))][3:]
27
+ value_18k = value_18k.split('\n')[0]
28
+
29
+ return value_24k, value_22k, value_18k
30
+ # List of cities
31
+ cities = ['Ahmedabad', 'Ayodhya', 'Bangalore', 'Bhubaneswar', 'Chandigarh', 'Chennai',
32
+ 'Coimbatore', 'Delhi', 'Hyderabad', 'Jaipur', 'Kerala', 'Kolkata', 'Lucknow',
33
+ 'Madurai', 'Mangalore', 'Mumbai', 'Mysore', 'Nagpur', 'Nashik', 'Patna',
34
+ 'Pune', 'Rajkot', 'Salem', 'Surat', 'Trichy', 'Vadodara', 'Vijayawada', 'Visakhapatnam']
35
+
36
+ # Sidebar content
37
+ st.sidebar.title("About the Project")
38
+ st.sidebar.write("This project fetches current gold rates for 24K, 22K, and 18K gold from GoodReturns for 28 Indian states. The rates for 1g, 8g, and 10g are displayed.")
39
+ st.sidebar.write("**Developed by:**")
40
+ st.sidebar.write("[Srish Rachamalla](https://www.linkedin.com/in/srishrachamalla/)")
41
+ st.sidebar.write("[Sai Teja Pallerla](https://www.linkedin.com/in/saiteja-pallerla-668734225/)")
42
+
43
+ # Main UI
44
+ st.title('Gold Rates in Indian Cities')
45
+ st.subheader('Select a city to view the current gold rates')
46
+
47
+ # Dropdown for city selection
48
+ selected_city = st.selectbox('Select a City', cities)
49
+
50
+ # Fetch and display gold rates
51
+ if selected_city:
52
+ city_url = f"https://www.goodreturns.in/gold-rates/{selected_city}.html"
53
+
54
+ # Fetch the prices using your backend function
55
+ try:
56
+ value_24k, value_22k, value_18k = price_cities(city_url)
57
+
58
+ # Convert string values to float for calculation
59
+ value_22k = round(float(value_22k.replace(',', '')),2)
60
+ value_24k = round(float(value_24k.replace(',', '')),2)
61
+ value_18k = round(float(value_18k.replace(',', '')),2)
62
+ # Prepare data for table
63
+ data = {
64
+ # 'SNO': [1, 2, 3],
65
+ 'Gold Purity': ['24K', '22K', '18K'],
66
+ '1g Price (₹)': [value_24k, value_22k, value_18k],
67
+ '8g Price (₹)': [value_24k * 8, value_22k * 8, value_18k * 8],
68
+ '10g Price ()': [value_24k * 10, value_22k * 10, value_18k * 10]
69
+ }
70
+
71
+ # Create a DataFrame for display
72
+ df = pd.DataFrame(data,index=[1, 2, 3])
73
+
74
+ # Display the DataFrame as a table
75
+ st.write(f"Gold rates in {selected_city}:")
76
+ st.dataframe(df.style.format(precision=2).set_properties(**{
77
+ 'background-color': 'black',
78
+ 'color': 'white',
79
+ 'border-color': 'ash'
80
+ }))
81
+
82
+
83
+ except Exception as e:
84
+ st.error(f"Could not fetch the gold rates. Please try again.{e}")
85
+
86
+ st.markdown("<br><hr><center><p style='color: grey;'>© 2024 All Rights Reserved</p></center><br>", unsafe_allow_html=True)
87
+
88
+