temperatureapp / app.py
karthikmn's picture
Create app.py
9403bdb verified
import gradio as gr
# Function for converting Celsius to Fahrenheit
def celsius_to_fahrenheit(temp_celsius):
return f"{temp_celsius}°C = {(temp_celsius * 9/5) + 32:.2f}°F"
# Function for converting Fahrenheit to Celsius
def fahrenheit_to_celsius(temp_fahrenheit):
return f"{temp_fahrenheit}°F = {(temp_fahrenheit - 32) * 5/9:.2f}°C"
# Gradio interface
def temperature_converter(temp, conversion_type):
if conversion_type == "Celsius to Fahrenheit":
return celsius_to_fahrenheit(temp)
elif conversion_type == "Fahrenheit to Celsius":
return fahrenheit_to_celsius(temp)
# Create the Gradio interface
interface = gr.Interface(
fn=temperature_converter,
inputs=[
gr.Number(label="Enter Temperature"),
gr.Radio(["Celsius to Fahrenheit", "Fahrenheit to Celsius"], label="Conversion Type"),
],
outputs="text",
title="Temperature Converter",
description="Convert temperatures between Celsius and Fahrenheit. Choose the conversion type and input the temperature.",
)
# Launch the app locally
if __name__ == "__main__":
interface.launch()