bikas commited on
Commit
20c801a
1 Parent(s): 42e355f

Currency Converter

Browse files
Files changed (4) hide show
  1. README.md +42 -13
  2. api.py +1 -4
  3. app.py +1 -1
  4. frankfurter.py +2 -21
README.md CHANGED
@@ -1,13 +1,42 @@
1
- ---
2
- title: Currency Converter
3
- emoji: 🔥
4
- colorFrom: indigo
5
- colorTo: purple
6
- sdk: streamlit
7
- sdk_version: 1.39.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Currency Converter Web App
2
+
3
+ ## Author:
4
+ - **Name**: [Your Name]
5
+ - **Student ID**: [Your Student ID]
6
+
7
+ ## Project Description:
8
+
9
+ This project is a Currency Converter web app built using Python and Streamlit. It allows users to convert between different currencies using both the latest and historical exchange rates retrieved from the Frankfurter API.
10
+
11
+ ### Key Features:
12
+ 1. Convert an amount between two currencies using the latest conversion rate.
13
+ 2. Convert an amount using a historical exchange rate for a selected date.
14
+ 3. Display the conversion rate, converted amount, and inverse conversion rate.
15
+
16
+ ### Files in the Project:
17
+ - **app.py**: Main Streamlit Python script used for managing users’ inputs and displaying results.
18
+ - **api.py**: Python script that contains the code for making API calls to fetch available currencies.
19
+ - **frankfurter.py**: Python script containing functions for calling relevant Frankfurter endpoints and extracting information (latest and historical rates).
20
+ - **currency.py**: Python script used for formatting the results displayed in the Streamlit app.
21
+ - **README.md**: Project documentation with details, functions list, and instructions for running the web app.
22
+
23
+ ### Python Functions:
24
+ - `get_currencies()`: Fetches the list of available currencies from the Frankfurter API.
25
+ - `get_latest_rate(from_currency, to_currency)`: Fetches the latest conversion rate from the Frankfurter API.
26
+ - `get_historical_rate(from_currency, to_currency, date)`: Fetches the historical conversion rate for a specific date from the Frankfurter API.
27
+ - `format_conversion_result(date, from_currency, to_currency, rate, from_amount, to_amount, inverse_rate)`: Formats the conversion results for display in the Streamlit app.
28
+
29
+ ### How to Run the Web App:
30
+ Install the required dependencies:
31
+
32
+ ```bash
33
+ pip install streamlit requests
34
+ or
35
+ pip install -r requirements.txt
36
+ ```
37
+
38
+ Run the Streamlit app:
39
+
40
+ ```bash
41
+ streamlit run app.py
42
+ ```
api.py CHANGED
@@ -3,10 +3,7 @@ import requests
3
  BASE_URL = "https://api.frankfurter.app"
4
 
5
  def get_currencies():
6
- """
7
- Fetch the list of available currencies from Frankfurter API.
8
- Returns a list of currency codes.
9
- """
10
  response = requests.get(f"{BASE_URL}/currencies")
11
  if response.status_code == 200:
12
  currencies = response.json()
 
3
  BASE_URL = "https://api.frankfurter.app"
4
 
5
  def get_currencies():
6
+
 
 
 
7
  response = requests.get(f"{BASE_URL}/currencies")
8
  if response.status_code == 200:
9
  currencies = response.json()
app.py CHANGED
@@ -10,7 +10,7 @@ st.title("Currency Converter")
10
  currencies = get_currencies()
11
 
12
  # Input elements
13
- amount = st.number_input("Enter the amount to be converted:", min_value=0.0, value=0.0)
14
  from_currency = st.selectbox("From currency:", currencies)
15
  to_currency = st.selectbox("To currency:", currencies)
16
 
 
10
  currencies = get_currencies()
11
 
12
  # Input elements
13
+ amount = st.number_input("Enter the amount to be converted:", min_value=0.0, value=100.0)
14
  from_currency = st.selectbox("From currency:", currencies)
15
  to_currency = st.selectbox("To currency:", currencies)
16
 
frankfurter.py CHANGED
@@ -3,16 +3,7 @@ import requests
3
  BASE_URL = "https://api.frankfurter.app"
4
 
5
  def get_latest_rate(from_currency, to_currency):
6
- """
7
- Fetch the latest conversion rate from Frankfurter API.
8
-
9
- Args:
10
- from_currency: Currency code to convert from.
11
- to_currency: Currency code to convert to.
12
-
13
- Returns:
14
- The latest conversion rate.
15
- """
16
  response = requests.get(f"{BASE_URL}/latest?from={from_currency}&to={to_currency}")
17
  if response.status_code == 200:
18
  data = response.json()
@@ -21,17 +12,7 @@ def get_latest_rate(from_currency, to_currency):
21
  raise Exception("Failed to fetch the latest rate")
22
 
23
  def get_historical_rate(from_currency, to_currency, date):
24
- """
25
- Fetch the historical conversion rate for a specific date from Frankfurter API.
26
-
27
- Args:
28
- from_currency: Currency code to convert from.
29
- to_currency: Currency code to convert to.
30
- date: Date for which to fetch the rate (in YYYY-MM-DD format).
31
-
32
- Returns:
33
- The historical conversion rate.
34
- """
35
  response = requests.get(f"{BASE_URL}/{date}?from={from_currency}&to={to_currency}")
36
  if response.status_code == 200:
37
  data = response.json()
 
3
  BASE_URL = "https://api.frankfurter.app"
4
 
5
  def get_latest_rate(from_currency, to_currency):
6
+
 
 
 
 
 
 
 
 
 
7
  response = requests.get(f"{BASE_URL}/latest?from={from_currency}&to={to_currency}")
8
  if response.status_code == 200:
9
  data = response.json()
 
12
  raise Exception("Failed to fetch the latest rate")
13
 
14
  def get_historical_rate(from_currency, to_currency, date):
15
+
 
 
 
 
 
 
 
 
 
 
16
  response = requests.get(f"{BASE_URL}/{date}?from={from_currency}&to={to_currency}")
17
  if response.status_code == 200:
18
  data = response.json()