muhammadrazapathan's picture
Create app.py
68ba047 verified
raw
history blame contribute delete
847 Bytes
import gradio as gr
from forex_python.converter import CurrencyRates
c = CurrencyRates()
def convert_currency(amount, from_currency, to_currency):
try:
rate = c.get_rate(from_currency.upper(), to_currency.upper())
converted_amount = amount * rate
return f"{amount} {from_currency} = {converted_amount:.2f} {to_currency}"
except:
return "Error: Please enter valid currency codes like USD, PKR, EUR, INR."
interface = gr.Interface(
fn=convert_currency,
inputs=[
gr.Number(label="Amount"),
gr.Textbox(label="From Currency (e.g. USD)"),
gr.Textbox(label="To Currency (e.g. PKR)")
],
outputs="text",
title="💱 Currency Converter App",
description="Convert currency in real-time using live exchange rates."
)
if __name__ == "__main__":
interface.launch()