EngrSamad commited on
Commit
7d305e5
Β·
verified Β·
1 Parent(s): 7fed58e

Initial commit Added app.py and requirements.txt First upload

Browse files
Files changed (2) hide show
  1. app.py +149 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def cel_fah(c):
4
+ return (c * 1.8) + 32
5
+
6
+ def fah_cel(f):
7
+ return (f - 32) / 1.8
8
+
9
+ def cel_kel(c):
10
+ return c + 273.15
11
+
12
+ def kel_cel(k):
13
+ return k - 273.15
14
+
15
+ def fah_kel(f):
16
+ return (f - 32) / 1.8 + 273.15
17
+
18
+ def kel_fah(k):
19
+ return (k - 273.15) * 1.8 + 32
20
+
21
+ def explain_temp(temp, unit):
22
+ celsius = temp
23
+ if unit == "F":
24
+ celsius = fah_cel(temp)
25
+ elif unit == "K":
26
+ celsius = kel_cel(temp)
27
+
28
+ if celsius < 10:
29
+ return "❄️ <span style='color:#1e90ff'>It's very cold outside!</span>"
30
+ elif 10 <= celsius < 25:
31
+ return "🌀️ <span style='color:#2ecc71'>The weather is pleasant.</span>"
32
+ elif 25 <= celsius < 35:
33
+ return "β˜€οΈ <span style='color:#e67e22'>It's warm.</span>"
34
+ else:
35
+ return "πŸ”₯ <span style='color:#e74c3c'>It's hot!</span>"
36
+
37
+ def temperature_converter(choice, value):
38
+ if choice == "Celsius β†’ Fahrenheit":
39
+ result = f"{cel_fah(value):.2f} Β°F"
40
+ explain = explain_temp(value, "C")
41
+ elif choice == "Celsius β†’ Kelvin":
42
+ result = f"{cel_kel(value):.2f} K"
43
+ explain = explain_temp(value, "C")
44
+ elif choice == "Fahrenheit β†’ Celsius":
45
+ converted = fah_cel(value)
46
+ result = f"{converted:.2f} Β°C"
47
+ explain = explain_temp(value, "F")
48
+ elif choice == "Fahrenheit β†’ Kelvin":
49
+ converted = fah_kel(value)
50
+ result = f"{converted:.2f} K"
51
+ explain = explain_temp(value, "F")
52
+ elif choice == "Kelvin β†’ Celsius":
53
+ converted = kel_cel(value)
54
+ result = f"{converted:.2f} Β°C"
55
+ explain = explain_temp(value, "K")
56
+ elif choice == "Kelvin β†’ Fahrenheit":
57
+ converted = kel_fah(value)
58
+ result = f"{converted:.2f} Β°F"
59
+ explain = explain_temp(value, "K")
60
+ else:
61
+ return "⚠️ Invalid choice"
62
+
63
+ return f"<b>βœ… Result:</b> {result}<br><br>{explain}"
64
+
65
+ choices = [
66
+ "Celsius β†’ Fahrenheit",
67
+ "Celsius β†’ Kelvin",
68
+ "Fahrenheit β†’ Celsius",
69
+ "Fahrenheit β†’ Kelvin",
70
+ "Kelvin β†’ Celsius",
71
+ "Kelvin β†’ Fahrenheit"
72
+ ]
73
+
74
+ with gr.Blocks(css="""
75
+ body {
76
+ background: linear-gradient(135deg, #c3ec52, #0ba29d);
77
+ }
78
+ .title {
79
+ font-size: 45px;
80
+ font-weight: bold;
81
+ text-align: center;
82
+ margin-bottom: 10px;
83
+ }
84
+ .title span {
85
+ background: linear-gradient(90deg, #00c6ff, #0072ff);
86
+ -webkit-background-clip: text;
87
+ -webkit-text-fill-color: transparent;
88
+ }
89
+ .desc {
90
+ color: #003566;
91
+ text-align: center;
92
+ font-size: 20px;
93
+ font-style: italic;
94
+ margin-bottom: 30px;
95
+ }
96
+ .card {
97
+ background: white;
98
+ border-radius: 20px;
99
+ padding: 30px;
100
+ box-shadow: 0px 8px 25px rgba(0,0,0,0.15);
101
+ margin: auto;
102
+ width: 60%;
103
+ transition: transform 0.3s ease;
104
+ }
105
+ .card:hover {
106
+ transform: scale(1.02);
107
+ }
108
+ .gr-textbox textarea {
109
+ background-color: #f0f9ff;
110
+ color: #222;
111
+ font-weight: bold;
112
+ font-size: 18px;
113
+ border-radius: 10px;
114
+ }
115
+ .gr-button {
116
+ background: linear-gradient(90deg, #36d1dc, #5b86e5) !important;
117
+ color: white !important;
118
+ font-size: 18px !important;
119
+ font-weight: bold !important;
120
+ border-radius: 14px !important;
121
+ transition: 0.3s;
122
+ }
123
+ .gr-button:hover {
124
+ background: linear-gradient(90deg, #5b86e5, #36d1dc) !important;
125
+ transform: scale(1.08);
126
+ }
127
+ .footer {
128
+ margin-top: 30px;
129
+ text-align: center;
130
+ color: #222;
131
+ font-size: 14px;
132
+ font-style: italic;
133
+ }
134
+ """ ) as demo:
135
+
136
+ gr.HTML("<div class='title'>🌑️ <span>Temperature Converter</span></div>")
137
+ gr.HTML("<div class='desc'>Convert between Celsius, Fahrenheit, and Kelvin with live explanation ✨</div>")
138
+
139
+ with gr.Column(elem_classes="card"):
140
+ choice = gr.Dropdown(choices, label="🌐 Choose Conversion")
141
+ value = gr.Number(label="✏️ Enter Temperature")
142
+ result = gr.HTML(label="βœ… Result with Explanation")
143
+ btn = gr.Button("πŸš€ Convert")
144
+
145
+ btn.click(temperature_converter, inputs=[choice, value], outputs=result)
146
+
147
+ gr.HTML("<div class='footer'>πŸ’‘ Developed with ❀️ using Python & Gradio</div>")
148
+
149
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio