awais0300 commited on
Commit
bc904d8
·
verified ·
1 Parent(s): 56fde48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -56
app.py CHANGED
@@ -1,59 +1,61 @@
1
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
2
 
3
  # Title of the app
4
- st.title("Temperature Converter")
5
-
6
- # Sidebar for user inputs
7
- st.sidebar.header("Select Conversion")
8
- from_unit = st.sidebar.selectbox("From Unit", ["Celsius", "Fahrenheit", "Kelvin"])
9
- to_unit = st.sidebar.selectbox("To Unit", ["Celsius", "Fahrenheit", "Kelvin"])
10
-
11
- # Input for temperature
12
- temperature = st.number_input(f"Enter temperature in {from_unit}", value=0.0)
13
-
14
- # Conversion Functions
15
- def celsius_to_fahrenheit(celsius):
16
- return (celsius * 9/5) + 32
17
-
18
- def celsius_to_kelvin(celsius):
19
- return celsius + 273.15
20
-
21
- def fahrenheit_to_celsius(fahrenheit):
22
- return (fahrenheit - 32) * 5/9
23
-
24
- def fahrenheit_to_kelvin(fahrenheit):
25
- return (fahrenheit - 32) * 5/9 + 273.15
26
-
27
- def kelvin_to_celsius(kelvin):
28
- return kelvin - 273.15
29
-
30
- def kelvin_to_fahrenheit(kelvin):
31
- return (kelvin - 273.15) * 9/5 + 32
32
-
33
- # Logic to perform conversion
34
- if from_unit == "Celsius":
35
- if to_unit == "Fahrenheit":
36
- converted_temp = celsius_to_fahrenheit(temperature)
37
- elif to_unit == "Kelvin":
38
- converted_temp = celsius_to_kelvin(temperature)
39
- else:
40
- converted_temp = temperature # No conversion needed if the same unit
41
-
42
- elif from_unit == "Fahrenheit":
43
- if to_unit == "Celsius":
44
- converted_temp = fahrenheit_to_celsius(temperature)
45
- elif to_unit == "Kelvin":
46
- converted_temp = fahrenheit_to_kelvin(temperature)
47
- else:
48
- converted_temp = temperature # No conversion needed if the same unit
49
-
50
- elif from_unit == "Kelvin":
51
- if to_unit == "Celsius":
52
- converted_temp = kelvin_to_celsius(temperature)
53
- elif to_unit == "Fahrenheit":
54
- converted_temp = kelvin_to_fahrenheit(temperature)
55
- else:
56
- converted_temp = temperature # No conversion needed if the same unit
57
-
58
- # Display the result
59
- st.write(f"{temperature} {from_unit} is equal to {converted_temp:.2f} {to_unit}")
 
1
  import streamlit as st
2
+ from PIL import Image, ImageEnhance
3
+ import io
4
+
5
+ # Function to show image
6
+ def show_image(img):
7
+ st.image(img, caption="Edited Image", use_column_width=True)
8
+
9
+ # Function to reset the image to the original state
10
+ def reset_image():
11
+ st.session_state["image"] = st.session_state["original_image"]
12
 
13
  # Title of the app
14
+ st.title("Image Editor and Reset Tool")
15
+
16
+ # Sidebar for uploading the original image
17
+ st.sidebar.header("Upload Image")
18
+ uploaded_image = st.sidebar.file_uploader("Upload your image", type=["jpg", "jpeg", "png"])
19
+
20
+ # Save the original image in session state
21
+ if uploaded_image is not None:
22
+ img = Image.open(uploaded_image)
23
+
24
+ # Store the original image in session state
25
+ if "original_image" not in st.session_state:
26
+ st.session_state["original_image"] = img.copy()
27
+
28
+ st.session_state["image"] = img.copy()
29
+
30
+ show_image(st.session_state["image"])
31
+
32
+ # Options to edit the image
33
+ if uploaded_image is not None:
34
+ st.sidebar.header("Edit Image")
35
+
36
+ # Rotation
37
+ rotate_angle = st.sidebar.slider("Rotate image", 0, 360, 0)
38
+ if rotate_angle != 0:
39
+ st.session_state["image"] = st.session_state["image"].rotate(rotate_angle)
40
+
41
+ # Brightness Adjustment
42
+ brightness_factor = st.sidebar.slider("Brightness", 0.0, 2.0, 1.0)
43
+ enhancer = ImageEnhance.Brightness(st.session_state["image"])
44
+ st.session_state["image"] = enhancer.enhance(brightness_factor)
45
+
46
+ # Crop Image (User specifies the cropping box)
47
+ st.sidebar.subheader("Crop Image")
48
+ crop_x1 = st.sidebar.slider("Crop X1", 0, st.session_state["image"].width, 0)
49
+ crop_y1 = st.sidebar.slider("Crop Y1", 0, st.session_state["image"].height, 0)
50
+ crop_x2 = st.sidebar.slider("Crop X2", 0, st.session_state["image"].width, st.session_state["image"].width)
51
+ crop_y2 = st.sidebar.slider("Crop Y2", 0, st.session_state["image"].height, st.session_state["image"].height)
52
+ if crop_x1 < crop_x2 and crop_y1 < crop_y2:
53
+ st.session_state["image"] = st.session_state["image"].crop((crop_x1, crop_y1, crop_x2, crop_y2))
54
+
55
+ # Reset Image
56
+ if st.sidebar.button("Reset to Original"):
57
+ reset_image()
58
+ st.sidebar.success("Image reset to original.")
59
+
60
+ # Display the edited image
61
+ show_image(st.session_state["image"])