Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# Function for converting Celsius to Fahrenheit
|
| 4 |
+
def celsius_to_fahrenheit(temp_celsius):
|
| 5 |
+
return f"{temp_celsius}°C = {(temp_celsius * 9/5) + 32:.2f}°F"
|
| 6 |
+
|
| 7 |
+
# Function for converting Fahrenheit to Celsius
|
| 8 |
+
def fahrenheit_to_celsius(temp_fahrenheit):
|
| 9 |
+
return f"{temp_fahrenheit}°F = {(temp_fahrenheit - 32) * 5/9:.2f}°C"
|
| 10 |
+
|
| 11 |
+
# Gradio interface
|
| 12 |
+
def temperature_converter(temp, conversion_type):
|
| 13 |
+
if conversion_type == "Celsius to Fahrenheit":
|
| 14 |
+
return celsius_to_fahrenheit(temp)
|
| 15 |
+
elif conversion_type == "Fahrenheit to Celsius":
|
| 16 |
+
return fahrenheit_to_celsius(temp)
|
| 17 |
+
|
| 18 |
+
# Create the Gradio interface
|
| 19 |
+
interface = gr.Interface(
|
| 20 |
+
fn=temperature_converter,
|
| 21 |
+
inputs=[
|
| 22 |
+
gr.Number(label="Enter Temperature"),
|
| 23 |
+
gr.Radio(["Celsius to Fahrenheit", "Fahrenheit to Celsius"], label="Conversion Type"),
|
| 24 |
+
],
|
| 25 |
+
outputs="text",
|
| 26 |
+
title="Temperature Converter",
|
| 27 |
+
description="Convert temperatures between Celsius and Fahrenheit. Choose the conversion type and input the temperature.",
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Launch the app locally
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
interface.launch()
|