amasood commited on
Commit
05b9cdf
·
verified ·
1 Parent(s): e2ef354

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ # Predefined conversion rates (for demonstration purposes; use a live API for real-time rates)
4
+ conversion_rates = {
5
+ ("USD", "EUR"): 0.91,
6
+ ("USD", "INR"): 83.0,
7
+ ("USD", "GBP"): 0.79,
8
+ ("EUR", "USD"): 1.10,
9
+ ("EUR", "INR"): 91.0,
10
+ ("EUR", "GBP"): 0.87,
11
+ ("INR", "USD"): 0.012,
12
+ ("INR", "EUR"): 0.011,
13
+ ("INR", "GBP"): 0.0095,
14
+ ("GBP", "USD"): 1.27,
15
+ ("GBP", "EUR"): 1.15,
16
+ ("GBP", "INR"): 105.0,
17
+ }
18
+
19
+ # Conversion function
20
+ def convert_currency(amount, from_currency, to_currency):
21
+ if from_currency == to_currency:
22
+ return amount
23
+ return amount * conversion_rates.get((from_currency, to_currency), 1.0)
24
+
25
+ # Streamlit app
26
+ st.set_page_config(
27
+ page_title="Currency Converter",
28
+ page_icon="💱",
29
+ layout="centered"
30
+ )
31
+
32
+ # App title with icon
33
+ st.markdown(
34
+ "<h1 style='text-align: center; color: #33A1FF;'>💱 Currency Conversion App</h1>",
35
+ unsafe_allow_html=True
36
+ )
37
+ st.write("Convert amounts between different currencies with ease!")
38
+
39
+ # Sidebar for user input
40
+ st.sidebar.header("Conversion Options")
41
+ amount = st.sidebar.number_input("Enter the amount:", min_value=0.0, format="%.2f")
42
+
43
+ from_currency = st.sidebar.selectbox("From Currency:", ["USD", "EUR", "INR", "GBP"])
44
+ to_currency = st.sidebar.selectbox("To Currency:", ["USD", "EUR", "INR", "GBP"])
45
+
46
+ # Add a button for conversion
47
+ if st.sidebar.button("Convert"):
48
+ converted_amount = convert_currency(amount, from_currency, to_currency)
49
+ result = f"{amount:.2f} {from_currency} is equal to {converted_amount:.2f} {to_currency}."
50
+
51
+ # Display result with styled text
52
+ st.markdown(
53
+ f"<h3 style='text-align: center; color: #FF5733;'>{result}</h3>",
54
+ unsafe_allow_html=True
55
+ )
56
+
57
+ # Footer
58
+ st.markdown(
59
+ "<hr style='border: 1px solid #33A1FF;'>",
60
+ unsafe_allow_html=True
61
+ )
62
+ st.markdown(
63
+ "<p style='text-align: center;'>Made with ❤️ using Streamlit</p>",
64
+ unsafe_allow_html=True
65
+ )