File size: 1,114 Bytes
9403bdb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()